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

Popular posts from this blog

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -