Forests and updating attributes manually in a ruby ​​on rails?

I was wondering if anyone knows how to update files (add / remove / update attribute) created using a ruby-based escid generator.

For instance:

student name scaffold: string lastname: string

therefore, it will create associated files (controller, view, etc.) with name and name as string attributes. When you db: transfer the project, it will create a table in the database. However, let's say I want to update, update it using the add attribute (like studenId: integer) or if it removes or updates the attribute, how do you do it?

I'm tired of just updating the generated files, but when I do this db: migrate, it still sets up the schema that is generated for what is in the table. Is there a built-in script in rails that will update the table?

Any recommendations evaluated? Thanks, D

+4
source share
4 answers

You need a new migration file for the new attributes from the console:

$ script/gnerate migration add_sudentid_to_sudent 

it will generate your_app / db / migrate / 8293898391_add_sudentid_to_sudent.rb, spicify your new attributes in this file:

 def self.up add_column :sudents, :studentId, :integer end def self.down remove_column :students, :studentsId end 

after that, back to the console:

 $ rake db:migrate 

and you can edit your views, models, controller files and use the new attribute

+1
source

The complete command in this example:

 $ rails generate migration add_studentid_to_student 
+2
source

Hi try ruby script/destroy scaffold student and then ruby script/generate scaffold student

+1
source

also try reading on migration flights to delete / update table columns. http://api.rubyonrails.org/classes/ActiveRecord/Migration.html

+1
source

Source: https://habr.com/ru/post/1316061/


All Articles