Dymanic changes for model name

Hello,

I have a question. But first take a look on this code:

Attachments <%= view_attachments_field(Garage.find(@partial_object_id), {}) %>

This code loading images for model Garage in my view by id. This is a
partial. And i used it in several places but for different models :City,
Shop, House…

I just don’t want to write code by Ctrl+Ins,Shift+Ins and do this
dynamically. I want to set model name in some controller and render this
partial for any model that support attachments.

I want something like this

Attachments <%= view_attachments_field(<>.find(@partial_object_id), {}) %>

How to do it?

Thanks

Who knows? :slight_smile:

Maybe this is a solution?

class A
def self.hello
puts “hello A”
end
end

class B
def self.hello
puts “hello B”
end
end

A.hello
B.hello

name1 = “A”
name2 = “B”

eval “#{name1}.hello”
eval “#{name2}.hello”

On 10/10/07, Igor K. [email protected] wrote:

How to do it?
Well, you can just pass the model class from your controller to the
partial through an instance variable or (better) through :locals. But
why not fetch the row in your controller and pass the actual object to
the partial instead of it’s class and id?
Maybe I’m missing something…

name1 = “A”
name2 = “B”

eval “#{name1}.hello”
eval “#{name2}.hello”

Better: name1.constantize

Fred