Search code examples
ruby-on-railspartial-viewspartiallocal-variables

Rails 3 local variable is not being passed to partial


has anyone an idea why I have the following problem with passing locals to a Ruby partial ?

My partial (excerpt):

 <div class="control-group">
   <%= field_prefix %>
   <%= label_tag t("shared.email"),nil,:class => "control-label" %>
   <div class="controls">
   <%= email_field_tag "[email]", contact.nil? ? "" : contact[:email]  %>
   </div>
 </div>

My partial is included in the following way:

 <%= render "shared/contact", :field_prefix => 123 , :contact => @person.contact %>

Also if i do it this way it wont`t work, the second local i pass (field_prefix) is not passed:

 <%= render :partial => "shared/contact", :locals => {:field_prefix => 123 , :contact => @person.contact } %>

I always get the error message that the local variable "field_prefix" is not recognized:

undefined local variable or method `field_prefix' for #<#:0x5837418>

It`s coming from the partial view.


Solution

  • most of the time I really like Ruby but sometimes it is very very annoying and mysterious :-/

    I had to restart my IDE (RubyMine) and the integrated server to get it working without chaning any source.

    Of course the sources were saved also yesterday when I tried it first but there seems to be a cache or something like that in this IDE.