繁体   English   中英

无法从产量中放入参数

[英]Can't puts parameter from yield

为什么我不能从yield中放参数?

错误:

undefined local variable or method `options' for #<#<Class:0x007fd1bd8735e8>:0x007fd1ba3e4fe8>

/app/helpers/bootstrap_form_helper.rb

...
  def inline
    options = "row_disable"
    content_tag(:div, class: "row test") { yield(options) }
  end
...

/app/views/signup/new.html.erb

...    
<%= inline do %>
  <%= options %>
  <%= person_f.text_field(:last_name, control_col: 7) %>
<% end %>
...

您无法访问inline方法中定义的局部变量 options 您必须访问通过inline方法传递给该块的参数 ,并且为此,需要在new.html.erb中让您的块接受一个options参数:

  ...    
  <%= inline do |options| %>
    <%= options %>
    <%= person_f.text_field(:last_name, control_col: 7) %>
  <% end %>
  ...

为了进一步说明,您甚至不需要在new.html.erb中将其称为options 以下内容也可以工作:

  ...    
  <%= inline do |foo| %>
    <%= foo %>
    <%= person_f.text_field(:last_name, control_col: 7) %>
  <% end %>
  ...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM