ruby on rails - How to iterate instance variables within instance variables in view? -


i'm using rails 3.2. have following code:

# transports_controller.rb @transports = %w(car bike)  @transports.each |transport|   instance_variable_set("@#{transport.pluralize}",                          transport.classify.constantize.all) end  # transports/index.html.erb <% @transports.each |transport| %>   <h1><%= transport.pluralize.titleize %></h1>   <% @transport.pluralize.each |transport_item| %>     <%= transport_item.name %><br>   <% end %> <% end %> 

the controller code correct, view code wrong. @transport.pluralize.each cannot called literally . expected result is:

<h1>cars</h1> ferrari<br> ford<br>  <h1>bikes</h1> kawasaki<br> ducati<br> 

how do this?

just use instance_variable_set, there instance_variable_get available.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -