Reputation: 1
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
Reputation: 15525
I can see multiple problems here:
status
hash.type
that contains a user_id
, which is inconsistent with your whitelisted attributes.type_id
that contains a String (and not an id).type
and type_id
conflicts because Rails will set these attributes on the Status
model and one will probably override the other.Upvotes: 1
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