Rails 4 - ActiveModel::ForbiddenAttributesError -


i have read other issues it, still can't point causing error. have defined strong parameters of rails 4, keeps showing error:

activemodel::forbiddenattributeserror in messagescontroller#create

my view this:

<%= form_for(@message) |f| %>     <div class="form-group field">   <%= f.label :phrase %>   <br/>   <%= f.text_field :phrase,  autofocus: true, class: 'form-control' %> </div> <div class="form-group field">   <%= f.label :date %>   <br/>   <%= f.date_field :date, class: 'form-control' %> </div> <div class="actions text-center">   <%= f.submit "submit", class: 'btn btn-default' %> </div> <% end %> 

my controller:

class messagescontroller < applicationcontroller  def today     @dates = message.all() end  def history     @messages = message.history_checker end  def new     @message = message.new end  def create     @message = message.new(params[:message])     if @message.save         flash[:notice] = "ok"         redirect_to root_path     else         render :action => 'new'     end end  private  def message_params   params.require(:message).permit(:phrase,:date) end  end 

the error points line 15 of controller @message = message.new(params[:message]). ideas?

you need use message_params instead of params[:message]:

@message = message.new(message_params) 

Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -