views:

27

answers:

3

Hi,

I was wondering if anyone knew how to update the files (adding/removing/updating an attribute) produced by using the scaffold generator in ruby on rails.

For example:

scaffold student name:string lastname:string

so this will create a the associate files (controller,view,etc) with name and lastname as string attributes. When you db:migrate the project, it'll create the table in the database. However, say I want to update whether it be update it with an addition attribue (ex. studenId:integer) or if its removing or updating an attribute, how do you do that?

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

Any advise appreciated? Thanks, D

+1  A: 

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

Bohdan Pohorilets
A: 

also try reading up on rails migrations, for dropping/updating table columns. http://api.rubyonrails.org/classes/ActiveRecord/Migration.html

paolo granada lim
A: 

You need new migration file for new attributes, from console:

$ script/gnerate migration add_sudentid_to_sudent

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

def self.up
  add_column :sudents, :studentId, :integer
end

def self.down
 remove_column :students, :studentsId
end  

after that, back to console:

$  rake db:migrate

and than you can edit your views, model, controller files and use new attribute

Meduza