任何人都可以看到這種表達形式有什麼問題嗎?Rails 4 - 簡單的形式參數
<%= simple_fields_for :article do |f| %>
<%=f.input :q, :nil, placeholder: "Search" %>
<% end %>
錯誤消息稱:
wrong number of arguments (3 for 1..2)
所以 - 我的更廣泛的代碼是:
文章#index.html.erb:
<div class="row">
<div class="col-md-10 col-md-offset-1">
<%= render 'articles/searchform' %>
</div>
<div class="col-md-10 col-md-offset-1">
<% Article.all.sort_by(&:created_at).in_groups_of(3) do |group| %>
</div>
<div class="row">
<% group.compact.each do |article| %>
<div class="col-md-4">
<div class="indexdisplay">
<%= image_tag article.image_url, width: '100%', height:
'200px' if article.image.present? %>
<div class="indexheading"> <%= link_to article.title, article %> </div>
<div class="indexsubtext"> <%= truncate(article.body, :ommission =>
"...", :length => 250) %></div>
</div>
</div>
<% end %>
</div>
<div class="row">
<%= link_to 'New Article', new_article_path %>
</div>
在我的觀點的文章#形式.html.erb
<div class="col-xs-10 col-xs-offset-1">
<%= simple_form_for(@article) do |f| %>
<%= f.error_notification %>
<div class="form-inputs">
<%= f.input :title, autofocus: true %>
<%= f.input :body, :label => "Post", :input_html => {:rows => 10} %>
<%= f.input :image, :label => "Add an image" %>
</div>
<div class="form-actions">
<%= f.button :submit, "Review a draft", :class =>
'formsubmit' %>
</div>
<% end %>
在文章#searchform.html.erb
<% f.simple_fields_for :article do |a| %>
<%=a.input :q, :nil, placeholder: "Search" %>
<% end %>
我得到這個錯誤:
undefined local variable or method `f' for #<#<Class:0x007f874133c410>:0x007f8740448058>
你能否提供完整的表單代碼? – Dusht
你在這個問題中有3個錯誤,你能描述你看到哪些錯誤,在哪一點? –
當我拿Nathanvda的建議,並添加一個f。到搜索形式,我得到的錯誤是最終未定義的本地'f'。這可能是因爲我將搜索表單部分添加到索引而不是主表單。不確定。 – Mel