Tag: 当地人

Rails 3,将局部变量传递给partial

可能重复: Rails:对将locals传递给partials的语法感到困惑 我想将局部变量(模型中没有相关字段)传递给partial。 # infos/index.html.erb ‘info’, :locals => {:info => first, :img_style => “original”} %> :img_style将是图像的html样式。 # infos/_info.html.erb img_style), info %> # and here goes code for normal iteration # etc 但它不起作用,它返回错误: # GET /infos/ undefined local variable or method `img_style’ for #<#:0xc470cc4> 它可以在不做多余部分的情况下完成吗? 对不起我的英语不好。 :P 编辑: 井模型信息没有:img_style字段 # db/schema.rb create_table “infos”, :force => true […]

rails fields_for使用多个本地生成部分生成未定义变量的部分

所有, 我遇到了标准fields_for设置的问题。 在我的“_form”部分我有: ‘comments/comment_fields’, :locals => {:f => cf, :tester => true} %> 在“_comment_fields”部分中,我有通常的字段,然后是我的测试变量: 当我删除测试器变量时,一切都运行良好。 一旦我添加测试变量,我就会收到此错误: ActionView :: Template :: Error(#Class的未定义局部变量或方法`tester’:0xa1f3664>:0xa1f1bd4>) 有没有其他人在使用具有多个本地的fields_for时遇到此问题? 为了详细说明,我的“_comment_fields”部分看起来像这样: “comment_content” %> 它仅从“_form”部分调用。