title: Parsing a static JSON file into a Rails object
body: <p>I'm trying to parse a static JSON file from my root directory into an already predefined object, but I'm getting confused on how to get the object to &quot;read&quot; each attribute within the JSON file and display it as its own. I hope I'm not making this more confusing from what it is?</p>
  <p>Some of my code:</p>
  <pre><code>   class PostsController &lt; ApplicationController
    # before_action :set_post, except: [:index, :show]
  
    # @@posts = File.read('app/assets/javascripts/flickr_feed.json')
    # @posts = JSON.parse(string)
  
    # GET /posts
    # GET /posts.json
    def index
      @posts = Post.all
      respond_to do |format|
        format.html
        format.json { render json: @@posts }
        # format.json { render json: @@posts }
      end
    end
  
    # GET /post/1
    # GET /post/1.json
    def show
      @post = @post.assign_attributes JSON.parse(File.read('app/assets/javascripts/flickr_feed.json'))
      respond_to do |format|
        format.html
        format.json { render json: @post }
      end
    end
    ...
  </code></pre>
  <p>If I go to <code>localhost:3000/posts.json</code> I see the desire output..</p>
  <pre><code>{
  &quot;title&quot;: &quot;Recent Uploads tagged potato&quot;,
  &quot;link&quot;: &quot;https://www.flickr.com/photos/tags/potato/&quot;,
  &quot;description&quot;: &quot;&quot;,
  &quot;modified&quot;: &quot;2015-11-21T08:41:44Z&quot;,
  &quot;generator&quot;: &quot;https://www.flickr.com/&quot;,
  &quot;posts&quot;: [ // before was &quot;items&quot;:
   {
    &quot;title&quot;: &quot;Hokkaido potato with butter&quot;,
    &quot;link&quot;: &quot;https://www.flickr.com/photos/taking5/22873428920/&quot;,
    &quot;media&quot;: {&quot;m&quot;:&quot;https://farm6.staticflickr.com/5813/22873428920_3cac20cc47_m.jpg&quot;},
    &quot;date_taken&quot;: &quot;2015-07-18T08:16:24-08:00&quot;,
    &quot;description&quot;: &quot; &lt;p&gt;&lt;a href=\&quot;https://www.flickr.com/people/taking5/\&quot;&gt;Taking5&lt;\/a&gt; posted a photo:&lt;\/p&gt; &lt;p&gt;&lt;a href=\&quot;https://www.flickr.com/photos/taking5/22873428920/\&quot; title=\&quot;Hokkaido potato with butter\&quot;&gt;&lt;img src=\&quot;https://farm6.staticflickr.com/5813/22873428920_3cac20cc47_m.jpg\&quot; width=\&quot;240\&quot; height=\&quot;180\&quot; alt=\&quot;Hokkaido potato with butter\&quot; /&gt;&lt;\/a&gt;&lt;\/p&gt; &lt;p&gt;Yummy.&lt;\/p&gt;&quot;,
    &quot;published&quot;: &quot;2015-11-21T08:41:44Z&quot;,
    &quot;author&quot;: &quot;nobody@flickr.com (Taking5)&quot;,
    &quot;author_id&quot;: &quot;58375502@N00&quot;,
    &quot;tags&quot;: &quot;japan hokkaido potato hakodate morningmarket&quot;
   }
  ]
  }
   ...
  </code></pre>
  <p>But if I go to the <code>posts#index</code> I don't see anything. I know I'm not parsing the data properly, but I'm getting confused on how to do that.</p>
  <p><strong>Summary:</strong> I would like to parse each <strong>item</strong> from JSON file so as to be able to do <code>post.title</code>, <code>post.description</code>, etc.</p>
  <p><strong>Edit:</strong> Update on code in the controller.</p>