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
Post a Comment