2014-09-29 5 views
0

강력한 매개 변수에 문제가 있습니다.강력한 매개 변수, 허용되지 않은 매개 변수

내 교체 된 매개 변수는 다음과 같습니다 전달되는

def post_params 
    params.require(:post).permit(:content, :user_id, :topic_id).merge(:user_id => get_user.id) 
end 

매개 변수는 다음과 같습니다

{"utf8"=>"✓", 
"authenticity_token"=>"5+OEnLgihamJC37BSn4r/spoiRmccJzHhe6eaeC2Fuc=", 
"post"=>{"topid_id"=>"10", 
"content"=>"awfawfaw"}} 

그리고 함수를 작성한다 :

def create 
    post = Post.new(post_params) 
    if post.valid? && post.save 
     redirect_to :controler => :topic, :action => :show, :topic => post.topic.id 
    end 
end 

enter image description here

콘솔에서 오류가 발생했습니다. 왜 허용되지 않는지 알고 싶습니다 topic_id. 당신이해야하는

입니다

:

+3

오타가 있습니다. 로그에'topic_id' 대신'topid_id'가 표시됩니다. – mccannf

+0

신의 축복을 부탁드립니다.) –

+0

오류 또는 텍스트를 화면 캡처하지 않을 때 도움이됩니다. 대신 텍스트를 복사하여 붙여넣고 합리적으로 읽을 수있는 형식으로 서식을 지정하십시오. –

답변

0

당신은 당신의 허용 PARAMS에 오타가

def post_params 
    params.require(:post).permit(:content, :user_id, :topic_id).merge(:user_id => get_user.id) 
end 

및 그것은해야한다 :

def post_params 
    params.require(:post).permit(:content, :user_id, :topid_id).merge(:user_id => get_user.id) 
end 

그러나 모델의 어떤 이름에 따라 달라집니다 모델에있는 속성 양식에서 오타를 사용하여 양식을 변경하거나 다른 곳에서 변경해야합니다.

관련 문제