Using a string to find a model name

Hi Rails,

I have a string in my controller that I want to make into a model name. EG:

Class LlamaController < ApplicationController   def addsomething     model = params[:model_name]     # Here, I would like to take the string in model and use it as a Model     @foo = Model.new   end end

Is this possible? Is there a better way?

Thanks --Dean

I have a string in my controller that I want to make into a model name. EG:

Class LlamaController < ApplicationController def addsomething    model = params[:model_name]    # Here, I would like to take the string in model and use it as a Model    @foo = Model.new end end

Is this possible? Is there a better way?

@foo = Class.const_get(model).new

I think.

Cool, thanks.

0 urzatron app/models % ../../script/console Loading development environment.

Class.const_get('User').new

=> #<User:0xf7151cd0 @attributes={"created_on"=>nil, "updated_on"=>nil, "password"=>"", "login"=>"", "css_style"=>"default"}, @new_record=true>

model.constantize

or

  model.camelize.constantize

Inflector magic...

Michael