You cannot test whether a certain key (:somevar) was present in the locals
hash passed to render using defined?(:somevar), due to the way template
compilation works in Rails.
But you can use the following pattern instead:
local_assigns.include?(:somevar)
-- stefan kaes
On Jan 30, 2008 4:18 AM, Andy Watts <[EMAIL PROTECTED]>
wrote:
>
> I've noticed this behavior in consecutive calls to the same partial.
>
> 1. render :partial => 'blah', :locals => {:somevar => true}
> 2. render :partial => 'blah'
>
> In the second call to the partial, "defined?(somevar)" will return
> true...even tho it wasn't in the locals passed in the render..
>
> I'd like to have optional locals on some of my partials.
> The current behavior requires me to always pass the local :somevar.
>
> Does this strike anyone else as an issue?
>
> cheers
> Andy
> --
> Posted via http://www.ruby-forum.com/.
>
> >
>
--
--
For rails performance tuning, see: http://railsexpress.de/blog
Subscription: http://railsexpress.de/blog/xml/rss20/feed.xml
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Core" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-core?hl=en
-~----------~----~----~----~------~----~------~--~---