我想显示在我的模型类型的视图注释形式(类型#显示)显示的form_for在放映视图注释方法
的路由定义如下
Rails.application.routes.draw do
devise_for :users
root to: "products#index"
resources :types do
member do
get :vote, :as => :vote
post "vote" => "types#vote"
get :comment, :as => :comment
post "comment" => "types#comment"
end
end
resources :models
resources :products
resources :brands
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
end
的评论方法在types_controller.rb
def comment
user = current_or_guest_user
@type = Type.find(params[:id])
user_review = params[:review]
@type.review(user_review, user)
redirect_to @type, notice: 'Thank you for your comment.'
end
我有麻烦的观点正确设置的form_for
<%= form_for comment_type_path(@type) do |f| %>
<div><h3>How likely are you to recommend our service to your friends, family or colleagues?</h3></div>
<div><h3>Can you please tell us why you gave us this score?</h3></div>
<div class="field-box">
<br>
<%= f.text_area :review, class: "form-control", rows: "4" %><br>
</div>
<div class="actions">
<%= f.submit 'Vote', class: 'btn-flat success new-product' %>
</div>
<% end %>
使我有以下错误: 没有路由匹配[POST] “/类型/ 5”
<%= form_for @type, url: comment_type_path(@type), method: :post do |f| %>
<div><h3>How likely are you to recommend our service to your friends, family or colleagues?</h3></div>
<div><h3>Can you please tell us why you gave us this score?</h3></div>
<div class="field-box">
<br>
<%= f.text_area :review, class: "form-control", rows: "4" %><br>
</div>
<div class="actions">
<%= f.submit 'Vote', class: 'btn-flat success new-product' %>
</div>
<% end %>
给
引发ArgumentError在类型#显示 显示/家/月/文件/补充/应用/视图/类型/ show.html.erb其中行#62提出:
错误的参数数目(0 2)
什么是'show.html.erb'的线62替换您
form_for
? ArgumentError可能是因为你的一些方法调用。你最后的'form_for'语法正确 – kiddorails<%= f.text_area:review,class:“form-control”,rows:“4”%>
– Jan
你能创建['gist'](https:// gist。 github.com)与您的整个视图和完整的回溯? – kiddorails