Stephen
Stephen

Reputation: 1

param is missing or the value is empty: status

When I try to submit a new status I get the below. I have a registration form that is working fine, not sure what is going on here. Appreciate the help.

def status_params
  params.require(:status).permit(:type_id, :user_id)
end

and

def create
  @status = Status.new(status_params)

  respond_to do |format|
    if @status.save

The request

{"utf8"=>"✓",
       "authenticity_token"=>"gZPV4FfSm2eb+pGPbAAqI4zA/LHJiAsRkHdJar/aU3G63oBiaLr55zPoRv3K+7EmelN2Nofj/CTZ+qPtoYih5w==",
     "type"=>{"user_id"=>"3"},
     "type_id"=>"Ocular",
     "commit"=>"Create Status"}

My View

  <div class="field">
    <%= f.label :user_id %><br>
    <%= select(:user_id, @user_options) %>
  </div>

  <div class="field">
    <%= f.label :type_id %><br>
    <%= select_tag :type_id, options_for_select(mg_types) %>
  </div>

Upvotes: 0

Views: 594

Answers (2)

zwippie
zwippie

Reputation: 15525

I can see multiple problems here:

  1. The posted parameters are not wrapped in a status hash.
  2. You are posting an attribute hash called type that contains a user_id, which is inconsistent with your whitelisted attributes.
  3. You are also posting an attribute called type_id that contains a String (and not an id).
  4. Posting both type and type_id conflicts because Rails will set these attributes on the Status model and one will probably override the other.

Upvotes: 1

Amit Suroliya
Amit Suroliya

Reputation: 1545

Your params are not in status hash. So, Try this -

 def status_params
   params.permit(:type_id, type[:user_id])
 end

Upvotes: 2

Related Questions