2014-01-12 2 views
0

레일 4 개의 강력한 매개 변수를 사용하는 동안 오류가 발생했습니다.param을 (를) 찾을 수 없습니다. rails4 강력한 매개 변수에서

ActionController::ParameterMissing at /questions 
param not found: question 

나는 Question modelquestions controller 있습니다.

def index 
    @question = Question.new(question_params) 
    @questioner = Questioner.new(questioner_params) 
end 

첫째, 더 questioner_params 없다 : 질문 표는이 문제는 컨트롤러의 index 액션에 questions controller

class QuestionsController < ApplicationController 
    def index 
    @question = Question.new(question_params) 
    @questioner = Questioner.new(questioner_params) 
    end 

    def new 
    @question = Question.new(question_params) 
    end 

    def edit 
    @question = find(params[:id]) 
    raise "Question Not edited!" unless @question 
    end 

    def create 
    @question = Question.new(question_params) 

    respond_to do |wants| 
     if @question.save 
     flash[:notice] = 'You have successfully posted the questions!' 
     wants.html { redirect_to(root_path) } 
     wants.xml { render :xml => @question, :status => :created, :location => @question } 
     else 
     flash[:error] = "Please review the problems below." 
     wants.html { redirect_to(questions_path) } 
     wants.xml { render :xml => @question.errors, :status => :unprocessable_entity } 
     end 
    end 
    end 

    private 

    def question_params 
     params.require(:question).permit(:content) 
    end 
end 

답변

0

에 포함되는 것입니다 content column

있습니다. 더 중요한 것은 인덱스 작업에 대한 매개 변수가 없다는 것입니다. rake routes의 출력을 살펴보십시오. index는 모든 질문 모음을 표시하는 데 사용되므로 @question = Question.new 대신 @questions = Question.all을 색인 작업으로 정의 해보십시오.

확인이 밖으로도, 그것이 좋은 읽기와 당신이 막 시작 할 때 정말 도움이 :

http://guides.rubyonrails.org/getting_started.html 
+0

색인 페이지에 2 개의 양식이 있습니다. 하나는 질문과 다른 질문자를 사용합니다 – ben

-1

데프 쇼는? 질문 컨트롤러에서 매우 중요해 보입니다. ([: ID] PARAMS)

데프
@question = Question.find 보여

을 시도 당신은 questioner_params를 사용하는

+0

David 저는 답변을 고맙게 생각하지만 show action은 하나의 질문에 대한 자세한 내용을 표시하는 데 사용됩니다. – ben

2


말을하지만 그것은 어디 정의 아닙니다. 게다가 인덱스 작업을 표시 할 때는 매개 변수를 설정하지 않습니다. 사용자가 제출 작업을 수행해야하는 제출을 클릭 할 때만 매개 변수를 입력하면됩니다.

def index 
    @question = Question.new 
    @questioner = Questioner.new 
end 
+0

덕분에, 그것은 – ben

+0

을 도왔지만, 이제 나는 정의되지 않은'question '오류가 발생했습니다. plz check http://stackoverflow.com/questions/21101512/undefined-method-model-name-question-for-rails-4 그리고 가능하면 도움을줍니다. – ben

관련 문제