>From the docs:

===============

If the objects cannot be located as instance variables, you can add an extra
:object parameter which gives the actual object (or array of objects to
use):

  error_messages_for 'user', :object => @question.user

===============

If using the :object key, it bypasses that line you mentioned altogether:

 if object = options.delete(:object)
           objects = [object].flatten
 else
           objects = params.collect {|object_name|
instance_variable_get("@#{object_name}") }.compact
 end

Never tried it, but that should work :)

--
Adam Grant
Lead Web Engineer
Telaeris, Inc.
[email protected]
(858) 627-9710


On Thu, Jul 16, 2009 at 11:23 AM, Glenn Little <[email protected]> wrote:

>
> I'd like to call error_messages_for() in a partial.
> error_messages_for at some point does this:
>
>  objects = params.collect {|object_name|
> instance_variable_get("@#{object_name}") }.compact
>
> Basically, it needs to be pointed to an instance variable, not passed
> an object itself.  However, partials give you local vars, not instance
> vars.
>
> I can explicitly create an instance var like this:
>
>  (in _author.rhtml):
>
>   @author = author
>   ...
>   <%= error_messages_for(:author) %>
>   ...
>
> But that seems clunky.  I'm just wondering if there's a more
> rails-approved (tm) idiom for doing this?
>
> Thanks.
>
>        -glenn
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
SD Ruby mailing list
[email protected]
http://groups.google.com/group/sdruby
-~----------~----~----~----~------~----~------~--~---

Reply via email to