2

I have some JSON saved ina database that I am retrieving and parsing but for some reason cannot loop through the parsed JSON and return it's values.

<% @submission.each do |submission| %>
 <div class="field">
  <p class="submissionDate">
    <% @dog = JSON.parse(submission.self_interests) %> #Gets the JSON from the self_interests field
      <% @dog.each do |self_interests| %>
        <%= self_interests.company_name %>  #trying to get the company_name from the parsed array
     <% end %>
  </p>
<% end %>

if I use <%= self_interests %> instead of <%= self_interests.company_name %> it outputs the parsed array as expected.

{"self_interest"=>{"appointment_date"=>"2012-07-19", "company_name"=>"asdasd", "company_registration"=>"asdas", "created_at"=>"2012-07-18T15:49:33+02:00", "date_deleted"=>nil, "date_registered"=>"2012-07-10", "date_terminated"=>"2012-07-27", "id"=>16, "trading_name"=>"asdasd", "transacting_with"=>1, "type_of_business"=>"asdasdasd", "updated_at"=>"2012-07-18T15:49:33+02:00", "user_id"=>2}}

Any help with this will be much appreciated, its been wracking my brain hard. I am quite new to Rails so it might be something obvious I am missing.

1 Answer 1

1

try this updated one

<%= self_interests["self_interest"]["company_name"] %>
Sign up to request clarification or add additional context in comments.

3 Comments

I tried this and although I did not get a Rails error, there was no output in the paragraph tag in the view.
ohh sorry I am updating the answer with correct solution, didn't read it properly try new updated answer.
Yes, perfect. Thank you so much, I can't believe I didn't think of that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.