Controller not accepting params value but the same value hard coded is accepted
Posted
by
Numbers
on Stack Overflow
See other posts from Stack Overflow
or by Numbers
Published on 2014-05-27T20:38:15Z
Indexed on
2014/05/27
21:27 UTC
Read the original article
Hit count: 210
Rails.logger.info(params[:question])
=> {"title"=>"katt"}
@question_list.questions.create(params[:question])
=> ActiveModel::ForbiddenAttributesError (ActiveModel::ForbiddenAttributesError)
@question_list.questions.create("title"=>"katt")
# SUCCES!
I cannot understand why Rails not accepts the params when the exact same value written by hand works fine?
Update
controller:
def new_question
@question_list.questions.create(params[:question])
render nothing: true
end
private
def set_question_list
@question_list = QuestionList.find(params[:id])
end
def question_list_params
params.require(:question_list).permit(questions_attributes: [:id, :question_list_id, :title, :position, :_destroy])
end
view:
<%= form_for @question_list, url: new_question_question_list_path, remote: true do |f| %>
<%= f.text_field :title %>
<%= f.submit %>
<% end %>
© Stack Overflow or respective owner