Reputation: 3489
I've got an object/param that I'm saving into my database. But while I do that I'd like to get the first row in that object to do some Javascript things with. So what I'm receiving in my view from the Javascript object(Which is being send by an AJAX request) if i do this:
<% @markers.each do |marker| %>
<%= marker%>
<% end %>
Is this record:
["triplocations_attributes", {"0"=>{"latlng"=>"53.20192541983673, 5.535024029052693", "title"=>"first", "description"=>"first"}, "1"=>{"latlng"=>"53.18896756239149, 5.536568981445271", "title"=>"2nd", "description"=>"2nd"}}]
Now, what I would like is to get the latlng from the first(0) row. Can anyone tell me how?
What I've tried so far didn't work:
<%= marker.triplocations_attributes %>
<%= marker[0].title %>
<%= marker.title %>
Upvotes: 0
Views: 880
Reputation: 16435
It seems reasonable to suppose that you have something like
class Marker < ActiveRecord::Base
has_many :triplocations
...
end
In that case you need to access
marker.triplocations[0].title
marker.triplocations[0].description
...
Upvotes: 1