Rails 3局部变量未传递给partial [英] Rails 3 local variable is not being passed to partial

查看:96
本文介绍了Rails 3局部变量未传递给partial的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道为什么将本地人传递给Ruby局部组件时会有以下问题吗?

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

我的部分(摘录):

 <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 %>

如果我用这种方式也行不通,第二个我通过的本地(field_prefix)也不会通过:

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 } %>

我总是收到错误消息,指出无法识别局部变量"field_prefix":

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

#<#:0x5837418>的未定义局部变量或方法`field_prefix'

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

它来自局部视图.

推荐答案

大多数时候我真的很喜欢Ruby,但有时它非常令人讨厌和神秘:-/

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

我必须重新启动我的IDE(RubyMine)和集成服务器,以使其在不更改任何源代码的情况下工作.

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

当然,昨天我第一次尝试时也保存了源代码,但是在此IDE中似乎存在缓存或类似内容.

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.

这篇关于Rails 3局部变量未传递给partial的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆