scaffold under rails2.0

来源:百度文库 编辑:神马文学网 时间:2024/04/27 22:06:09
摘录自http://fairleads.blogspot.com/2007/12/rails-20-and-scaffolding-step-by-step.html
In Rails 2.0 it willtake fewer steps, but may be a little harder to follow because so muchis accomplished with so few commands. First we need to think about themovie inventory table.
Startsimple. Movies should have, at minimum a title, a description and amovie poster. Columns for other data like release date, rating orquantity on hand can be added later by altering the table through migrations. The next step is to create a model whose job will be to manage the data stored in the database.
The following command will generate the model, plus scaffolding, and the database migration script needed as well as a controller, helper, and testing support files:
exchange$ ruby script/generate scaffold Movie title:string description:text one_sheet_url:string
exists app/models/
exists app/controllers/
exists app/helpers/
create app/views/movies
exists app/views/layouts/
exists test/functional/
exists test/unit/
create app/views/movies/index.html.erb
create app/views/movies/show.html.erb
create app/views/movies/new.html.erb
create app/views/movies/edit.html.erb
create app/views/layouts/movies.html.erb
create public/stylesheets/scaffold.css dependency model
exists app/models/
exists test/unit/
exists test/fixtures/
create app/models/movie.rb
create test/unit/movie_test.rb
create test/fixtures/movies.yml
create db/migrate
create db/migrate/001_create_movies.rb
create app/controllers/movies_controller.rb
create test/functional/movies_controller_test.rb
create app/helpers/movies_helper.rb
route map.resources :movies
Making Movies
The table will get created by the file in db/migrate/001_create_movies.rb .