ruby on rails - How do I create instance variables from an array? -


i'm using rails 3.2. here's code:

transports = %w(car bike)  transports.each |transport|   @transport = transport.classify.all end 

that code not working, want results be:

@cars = car.all @bikes = bike.all 

how do that?

transports.each |transport|   instance_variable_set("@#{transport}",                          transport.classify.constantize.all) end 

update given entries in transports array singular correct code result want is

transports.each |transport|   instance_variable_set("@#{transport.pluralize}",                          transport.classify.constantize.all) end 

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 -