Rails has not added new fields to the database

  question, ruby

Having just touched Rails, following the tutorial on headfirst, I added a new field phone to an already created database, but it did not seem to be added. The code is as follows:

rails generate migration AddPhoneToTickets phone:string

And use migration:

rake db:migrate

The files under migrate under db under the project have also changed:

class AddPhoneToTickets < ActiveRecord::Migration[5.1]
 def change
 add_column :tickets, :phone, :string
 end
 end

However, it was not added when submitted on the webpage, as shown in the figure:
图片描述

Ask big brother to answer! ! Thank you very much

It should be that the newly added attribute is not whitelisted.

Rails has a feature called robust parameters (http://guides.rubyonrails.org …), Active Model cannot directly use params for batch assignment, and only whitelisted parameters will be read by Active Model.

You can check that there should be a method called user_params in UsersController. This method is to whitelist the parameters in params. You can try adding: phone.