【发布时间】:2018-03-11 04:45:54
【问题描述】:
我正在尝试在我的类型模型 (types#show) 视图中显示评论表单
路由定义如下
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] "/types/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 %>
给了
类型中的参数错误#show 显示 /home/jan/Documents/supplement/app/views/types/show.html.erb 其中第 62 行提出:
参数数量错误(0 代表 2)
【问题讨论】:
标签: ruby-on-rails routes form-for