2017-10-08 14 views
1

何も解決されていない状態で数時間作業しています。Rails 5:paramが見つからないか、値が空です。verbalquestions

class VerbalquestionsController < ApplicationController 

before_action :authenticate_user! 

def index 
@verbalquestions = Verbalquestion.all 

if params[:tag] 
    @verbalquestions = Verbalquestion.tagged_with(params[:tag]) 
else 
    @verbalquestions = Verbalquestion.all 
    end 
    end 

    def new 
    @title = "Add a new VQ" 
    end 

def show 
    @verbalquestion = Verbalquestion.friendly.find(params[:id]) 
    end 

def create 
    @verbalquestion = Verbalquestion.new(verbalquestion_params) 
    @verbalquestion.user = current_user 

end 
end 

private 
    def verbalquestion_params 
    params.require(:verbalquestions). 
    permit(
    :vq_title, 
    :vq_text, 
    :tag_list 
) 

end 

verbalquestions/new.html verbalquestions_controller.rb ActionController::ParameterMissing at /verbalquestions param is missing or the value is empty: verbalquestions

:私は新しいverbalquestionのリソースをロードし、私はフォームに必要事項を記入し、提出ヒットWhenenever、私はのエラーを取得します。エルブ

<%= form_with scope: :verbalquestion, url: verbalquestions_path do |f| %> 

<div class='field'> 
    <%= f.label :tag_list, 'Tags (separated by commas)' %><br/> 
    <%= f.text_field :tag_list %> 
</div> 


<div class="field"> 
    <%= f.label "Verbal Question Title", :class=>'label' %> 
    <div class="control"> 
    <%= f.text_field :vq_title, :id => 'vq_title', :class => 'textarea' %> 
    </div> 
</div> 

<div class="field"> 
    <%= f.label "Verbal Question Test", :class=>'label' %> 
    <div class="control"> 
    <%= f.text_area :vq_text, :id => 'vq_text', :class => 'textarea' %> 
    </div> 
</div> 


    <p> 
    <%= f.submit %> 
    </p> 


    <% end %> 

私は間違っていますか?

答えて

1

あなたのコントローラーがあなたのビューとcontroller>new@verbalquestion = Verbalquestion.new()form_for @verbalquestionを試すことができるのparams
params.require(:verbalquestions)

の 'verbalquestions' を必要とするからです。

また、params.require(:verbalquestions)は、params.require(:verbalquestion)のような単数形である必要があります。

+0

しかしコントローラには、このように設定されたパラメータがあります。 'private def verbalquestion_params params.require(:verbalquestions)。 許可証( :vq_title、 :vq_text、 :tag_list ) end' また、のform_forそれはレール5.1アプリですと何もしません。私は何をすべきか? – mazing

+0

私がすでに答えているので、 '@verbalquestion = Verbalquestion.new()'をコントローラの 'new'メソッドに追加してください。 また、あなたのビューで 'form_for @ verbalquestion'を使うこともできますし、' form_with model:@ verbalquestion'を自分の好みで使うこともできます。 – alex

+0

私はそれをすべてやっているし、うまくいきません。それでも 'ActionController :: ParameterMissing at/verbalquestions paramが見つからないか、値が空です:verbalquestions' – mazing

関連する問題