簡體   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