How do I access the flash from a partial template? I have the following in my layout: <%= render(:partial=>''files'', :object=>@property) %> I''ve tried adding the flash to the locals, but still can''t seem to access it. <%= render(:partial=>''files'', :object=>@property, :locals=>{:flash=>@flash}) %> I then have the following in my _files.rhtml <% if @flash[:error] %> <p><%= @flash[:error] %></p> <% end %> But this doesn''t seem to show up. If I place that in the layout itself, the flash appears, so I know it''s available to the page. Thanks. -- R.Livsey http://livsey.org
On Aug 2, 2005, at 7:06 AM, Richard Livsey wrote:> How do I access the flash from a partial template? > > I have the following in my layout: > <%= render(:partial=>''files'', :object=>@property) %> > > I''ve tried adding the flash to the locals, but still can''t seem to > access it. > <%= render(:partial=>''files'', :object=>@property, :locals=> > {:flash=>@flash}) %> > > I then have the following in my _files.rhtml > > <% if @flash[:error] %> > <p><%= @flash[:error] %></p> > <% end %> >When you pass in an array of "locals" you are literally asking the #render method to create local variables within your partial. In other words, use local variables, not instance variables: <% if flash[:error] %> <p><%= flash[:error] %></p> <% end %> Duane Johnson (canadaduane)
Duane Johnson wrote:> On Aug 2, 2005, at 7:06 AM, Richard Livsey wrote: > >> How do I access the flash from a partial template? >> >> I''ve tried adding the flash to the locals, but still can''t seem to >> access it. >> <%= render(:partial=>''files'', :object=>@property, :locals=> >> {:flash=>@flash}) %> >> >> I then have the following in my _files.rhtml >> >> <% if @flash[:error] %> >> <p><%= @flash[:error] %></p> >> <% end %> >> > When you pass in an array of "locals" you are literally asking the > #render method to create local variables within your partial. In > other words, use local variables, not instance variables: > > <% if flash[:error] %> > <p><%= flash[:error] %></p> > <% end %>I should have mentioned that I tried this. It didn''t seem to work at the time, I''ll try it again in a bit and see if I can figure out what I was doing wrong. The partial is completely self contained though I take it? Any variables (like flash, session etc...) will have to be passed through to it? Thanks for the help. -- R.Livsey http://livsey.org