title: Rails 4 — How to populate a user model from JSON API?
body: <p>Firstly, I am new to rails so sorry if there is anything that I don't understand correctly. I am wondering how can I populate a model with data fetch thru an API.</p>
  
  <p><strong>Context: I am using a OAuth2 authentication with omniauth/devise.</strong></p>
  
  <p>In my User controller client-side (opposite to the provider), I fetched all users who logged in at least once is this "client app" and I want to display them. Obviously, anytime a new user logged in to the client app I don't store all his information in the client database to avoid duplicate. All I am storing is the user_id along with its access token.</p>
  
  <p>Therefore, I was thinking that after fetching all users data I could populate them to a user model before passing it to the view. What would be the best way of doing such a thing?
  I was looking into the Named Scope but it is not clear to me how to apply it to my particular scenario. For instance, it would be great to be able to fetch an populate all users in my model using something like this:</p>
  
  <pre><code># ApiRequest is a container class for HTTParty
  get = ApiRequest.new.get_users(User.all) // here "get" is a JSON array of all users data
  response = get.parsed_response['users']
  User.populate(response).all # would something like this possible? If yes, is Named Scope the appropriate solution?
  </code></pre>
  
  <p>Thank you very much in advance for you help.</p>