2017-09-29 47 views
0

我想显示在我的模型类型的视图注释形式(类型#显示)显示的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)

+0

什么是'show.html.erb'的线62替换您form_for? ArgumentError可能是因为你的一些方法调用。你最后的'form_for'语法正确 – kiddorails

+0

<%= f.text_area:review,class:“form-control”,rows:“4”%>
Jan

+0

你能创建['gist'](https:// gist。 github.com)与您的整个视图和完整的回溯? – kiddorails

回答

0

PLE ASE与下面的代码

<%= form_for @type, url: comment_type_path, method: "post" do |f| %>

+0

这给出了与上面相同的错误: 类型#中的参数错误#显示 显示/home/jan/Documents/supplement/app/views/types/show.html.erb其中行#62提出: 错误的参数数目(0 2) 在这一行 '<(%)= f.text_area:综述,类: “形式控制”,行: “4” %>
' – Jan

+0

尝试这个'<%​​= f.text_area(:review,class:“form-control”,rows:“4”)%>' – Asmita

+0

谢谢,还是一样的错误。我很困惑,为什么这会显示类型#show的参数错误和缺少哪些参数。这不显示从错误消息 – Jan

相关问题