Hello,
I have a question. But first take a look on this code:
<p>
<b>Attachments</b>
<%= view_attachments_field(Garage.find(@partial_object_id), {}) %>
</p>
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
<p>
<b>Attachments</b>
<%= view_attachments_field(<<MODEL
CLASS>>.find(@partial_object_id), {})
%>
</p>
How to do it?
Thanks
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Who knows? :) -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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"
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
> > name1 = "A" > name2 = "B" > > eval "#{name1}.hello" > eval "#{name2}.hello" > -- >Better: name1.constantize Fred --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 10/10/07, Igor K. <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> I want to set model name in some controller and render this > partial for any model that support attachments. > > I want something like this > <p> > <b>Attachments</b> > <%= view_attachments_field(<<MODEL CLASS>>.find(@partial_object_id), {}) > %> > </p> > > 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.... --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---