Rails 使用实例变量渲染带有局部变量的文件
我刚刚更新到 Rails 2.3.11。在早期版本中,我可以编写以下
render :file=>'console/users/show.html.erb', :locals => {:@user => @users.first}
不再有效的内容,相反,我需要编写
render :file=>'console/users/show.html.erb', :locals => {:user => @users.first}
这意味着访问文件中的用户,我将使用“user”,但在文件中我想使用实例变量@user,如下所示从控制器调用相同的显示文件并传递@user
有任何提示吗?
谢谢
I've just updated to Rails 2.3.11. In an earlier version I could write the following
render :file=>'console/users/show.html.erb', :locals => {:@user => @users.first}
which no longer works, instead I need to write
render :file=>'console/users/show.html.erb', :locals => {:user => @users.first}
which means to access the user in the file I would use 'user' but in the file I would like to use the instance variable @user as this same show file is called from the controller and passes @user
Any tips?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在调用
render
之前设置@user
:只有在传递局部变量时才应使用
:locals
选项。Set
@user
before callingrender
:The
:locals
option should only be used if you are passing local variables through.