[英]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.