ruby on rails - Accessing Model from html -
i have loop in page displays cities in model. lets new york city 1 of these cities , want access new york city. how access particular city instance model in rails?
<% @cities.each |city| %> <tr> <td><%= city.name %></td> <td><%= city.country %></td> <td><%= link_to 'show', city %></td> <td><%= link_to 'edit', edit_city_path(city) %></td> <td><%= link_to 'destroy', city, method: :delete, data: { confirm: 'are sure?' } %></td> </tr> <% end %>
use attribute of object access object in view:
for example, if name
attribute of city "new york city", say:
city.find_by_name("new york city")
of course, it's not super railsy in view, add to relevant controller action:
@newyork = city.find_by_name("new york city")
and use @newyork
in view.
Comments
Post a Comment