Re: Problem with layout for partials

morgler
2009-01-13T13:10:21Z

I tried the following workaround:

<%= render :partial => "profiles/private", :layout =>
''layout'', :locals => {:my_profile => @my_profile } %>

Now I can access the correct profile by using the local variable
"my_profile" in the _layout partial. But the question remains: How
come the @my_profile has a different value in the above view code than
in the _layout partial? Is this a bug in rails?

On 13 Jan., 13:48, morgler
<morg...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org>
wrote:
> I like the feature to have layouts even for partials now. But I have a
> problem related to this topic:
>
> My controller sets the variable @my_profile somewhere before
> rendering. In the view I have the following code:
>
> <%= debug @my_profile %>
> <% if me? %>
>   <%= render :partial => "profiles/private", :layout =>
''layout'' %>
> <% else %>
>   <%= render :partial => "profiles/public", :layout =>
''layout'' %>
> <% end %>
>
> The "debug" outputs the correct value. The two actual partials
are not
> important, but the _layout partial is where the trouble begins. In
> case this "if" renders the second option (the _public partial), I
can
> also trace the @my_profile in the _layout partial - everything is
> fine. However, if the above statement branches to the first option
> (_private partial), tracing the @my_profile variable in the _layout
> partial gives me a DIFFERENT value (actually another valid profile,
> but not the one it is supposed to be)! I have no idea, how @my_profile
> is set to a different value?! Is it possible for a controller action
> to happen in the middle of rendering a view? I can''t imagine that,
> since a partial has no action associate with it (and neither has a
> partial layout). Does anyone have an idea how this value could become
> set differently during the parital rendering process?
>
> I would appreciate any kind of help! Thanks.
--~--~---------~--~----~------------~-------~--~----~
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@googlegroups.com