Reputation: 143
Thanks for reading, new to rails but trying to build a form to pass parameters. However, after the parameters are entered into the form, the validation in the create page is not seeing it, and gives me an error. But the logs show that the parameter was entered... I'm using the simple_form gem as well.
Controller:
class FoundsController < ApplicationController
def index
@found = Found.all
end
def new
@found = Found.new
end
def create
@found = Found.new(found_params)
if @found.save
redirect_to "/founds#index"
else
render "new"
end
end
end
def found_params
params.require(:floc).permit(:ftitle, :fdescription, :fcontact)
end
New Form Page:
<h1>Founds#new</h1>
<p>Find me in app/views/founds/new.html.erb</p>
<%= simple_form_for @found do |form| %>
<%= form.input :floc, label: "floc" %>
<%= form.input :fcontact, label: "fcontact" %>
<%= form.input :fdescription, label: "fdescription" %>
<%= form.input :ftitle, label: "ftitle" %>
<%= form.button :submit %>
<% end %>
Error: param is missing or the value is empty: floc
def found_params
params.require(:floc).permit(:ftitle, :fdescription, :fcontact)
end
Request
Parameters:
{"utf8"=>"✓",
"authenticity_token"=>"bJ1bUhd3G8z4S1QV+XsEAHmOcdSQyQxVS0rOSAsq6YANvz9ED7lFTME6falij4nrXkWEypWsSnPW7k9YHFGhDQ==",
"found"=>{"floc"=>"location",
"fcontact"=>"contact",
"fdescription"=>"descript",
"ftitle"=>"title"},
"commit"=>"Create Found"}
Upvotes: 1
Views: 1612
Reputation: 4171
Everything looks fine except for the strong parameters
It should be params.require(:found).permit(:floc, :ftitle, :fdescription, :fcontact)
You are telling Rails that the params coming in must have the :found
key, nested under which are the params you actually care about. Of those parameters, only the ones that are permitted will get through. Params that are not permitted will not get through but not throw an error.
Upvotes: 2