Topic: Using a model name from a variable string?

Hi,
2 quick questions:

[code="ruby"]
@model = "User"
@data = @model.find(:all)
[/code]

and

[code="ruby"]
@relationship = "user"
@data = Model.@relationship.find(:all)
[/code]

Thoughts on how to do either of those would be great...

Thanks

Adam

Re: Using a model name from a variable string?

Try this:

@model.constantize.find(:all)
# or
@item.send(@relationship)

Railscasts - Free Ruby on Rails Screencasts

Re: Using a model name from a variable string?

Nice smile Thanks