1

I've just started learning RoR and i'm really stuck. I've created a new app and i'm trying to add a phone number field to a previously created form (Tickets). I've created the database, added a migration script using :

rails generate migration AddPhoneToTickets phone:string

plus migrated it using :

rake db:migrate

Last, i've added the field to all the relevant html.erb files. When I add a new record to the App, the phone attribute is showed and when I fill it in and click "Update" I receive the message : "Ticket was successfully updated." Unfortunately the phone number isn't saved in the DB and isn't displayed in the listings.

Looking forward to your help.

wurde
  • 2,487
  • 2
  • 20
  • 39

2 Answers2

2

Should be a problem of strong parameters: check in your TicketsController if your ticket_params method looks like this:

def tickets_params
   params.require(:ticket).permit(whatever_other_params, :phone)
end

YOu can also check if in your server log, when saving it is saying Unpermitted param.

Have a look here: http://edgeguides.rubyonrails.org/action_controller_overview.html#strong-parameters

sissy
  • 2,908
  • 2
  • 28
  • 54
  • thanks for the quick response. Unfortunately I don't have any params mentioned anywhere in the controller code. I'm not sure this is the case. – user3292652 Feb 25 '14 at 16:54
  • if you're using Rails 4 you sure have something like that in your controllers (Rails 4 is based on strong parameters), otherwise it shouldn't be possible for you tu update any of the params. Can you check it please? – sissy Feb 25 '14 at 17:01
0

If you're using Rails 4 look for ticket_params method in the controller and add :phone to .permit where the other attributes are listed

j-dexx
  • 10,286
  • 3
  • 23
  • 36