Nil in Database for Ruby on Rails -
i'm extremely new, , going through basic ruby rails tutorial except tweaking add fields , renaming calls articles @ contacts.
problem is, fine, except data being added in nil. here controller:
class contactscontroller < applicationcontroller def index @contacts = contact.all end def show @contacts = contact.find(params[:id]) end def new end def create @contacts = contact.new(contact_params) @contacts.save redirect_to @contacts end end private def contact_params params.require(:contacts).permit(:first_name, :last_name, :phone_number, :notes) end
my migrate file:
class createcontacts < activerecord::migration def change create_table :contacts |t| t.string :first_name t.text :last_name t.text :phone_number t.text :notes t.timestamps null: false end end end
and i'm looking in terminal , see this:
started post "/contacts" 127.0.0.1 @ 2015-07-16 14:38:54 -0700 processing contactscontroller#create html parameters: {"utf8"=>"✓", "authenticity_token"=>"5l/werimovbipaq4rgb6oj8tilhkvvy96gggrntzp2uwzxj6csmidshzs rqzxbqhjatp60qmurg7hwlly5hf/w==", "contacts"=>{"first_name"=>"hello", "last_name"=>"aagin", "phone_number"=>"1231313", "notes"=>"smsda"}, "commit"=>"save contacts"} unpermitted parameters: first_name, last_name, phone_number, notes
i think they're might 'unpermitted parameters' part, because there seems difference in caps there.
if see wrong, please let me know! thank you. edit = here's view:
<h1>new contact</h1> <%= form_for :contacts, url: contacts_path |f| %> <p> <%= f.label :first_name %><br> <%= f.text_field :first_name %> </p> <p> <%= f.label :last_name %><br> <%= f.text_field :last_name %> </p> <p> <%= f.label :phone_number %><br> <%= f.text_field :phone_number %> </p> <p> <%= f.label :notes %><br> <%= f.text_area :notes %> </p> <p> <%= f.submit %> </p> <% end %> <%= link_to 'back', contacts_path %>
you not consistent contacts , contact. change line to.
params.require(:contact).permit(:first_name, :last_name, :phone_number, :notes)
name variables according rails conventions co @contacts
should changed @contact
.
Comments
Post a Comment