Migrating app from php. and have this in the view:
<%=render :partial => "jt-test", :locals => {:info => "here is my info", :hide_location=>true} %>
<br /><br />
<%=render :partial => "jt-test", :locals => {:info => "here is my info"} %>
in _jt-test.html.erb:
My info:<br />
<%=info %>
<% if local_assigns.has_key? :hide_location %>
you want to hide location!
<% end %>
Is the local_assigns the proper / best way to do this? Can I have an unlimited number of local_assigns? Is there a local_assigns for the main view called from the controller?
thx
In the main view you’d just use normal action class variables (
@whatever_variable_name), and they’re assigned in the controller:You may have unlimited locals in a partial, but if there are a “lot”, you might be doing it wrong. consider using an encapsulating object, breaking up the template more, etc.
Rails exposes local variables to partials by their name (
infoandhide_locationin your case). You don’t need to look it up usinghas_key?. See the passing local variables docs in the layout and rendering guide.