[英]Can't puts parameter from yield
Why I can't puts parameter from yield? 为什么我不能从yield中放参数?
Error: 错误:
undefined local variable or method `options' for #<#<Class:0x007fd1bd8735e8>:0x007fd1ba3e4fe8>
/app/helpers/bootstrap_form_helper.rb /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 /app/views/signup/new.html.erb
...
<%= inline do %>
<%= options %>
<%= person_f.text_field(:last_name, control_col: 7) %>
<% end %>
...
You cannot access the local variable , options
, defined in the inline
method. 您无法访问
inline
方法中定义的局部变量 options
。 You have to access the argument passed to the block by the inline
method, and to do that you need to have your block in new.html.erb accept an options
argument: 您必须访问通过
inline
方法传递给该块的参数 ,并且为此,需要在new.html.erb中让您的块接受一个options
参数:
...
<%= inline do |options| %>
<%= options %>
<%= person_f.text_field(:last_name, control_col: 7) %>
<% end %>
...
Just to clarify a little further, you don't even need to call it options
in new.html.erb. 为了进一步说明,您甚至不需要在new.html.erb中将其称为
options
。 The following would also work: 以下内容也可以工作:
...
<%= inline do |foo| %>
<%= foo %>
<%= person_f.text_field(:last_name, control_col: 7) %>
<% end %>
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.