Saturday, 23 April 2011

Using ActiveScaffold with Rails 3.0


Setup Rails 3 project :
  1. rails new howto
  2. cd howto
  3. bundle install
  4. rake db:create
Setup ActiveScaffold (you will need a running git bash):
  1. rails plugin install git://github.com/vhochstein/active_scaffold.git
  2. rails g active_scaffold_setup [prototype| jquery]
Your choice if you would like to use prototype or jquery. Thanks to Rails 3.0 and the new unobtrusive Javascript approach. If you are asked if you would like to overwrite rails.js just say yes.
Setup two activescaffolds:
  1. rails g active_scaffold Team name:string position:integer
  2. rails g active_scaffold Player name:string injured:boolean salary:decimal date_of_birth:date  team:references
  3. rake db:migrate
  4. edit file app/models/team.rb -> has_many :players
  5. edit file /app/views/layouts/application.html.erb->     
    <%= javascript_include_tag :defaults %>
    <%= active_scaffold_includes %>
  6. Add this to ur controller     active_scaffold :<your_model_name>
  7. Add :active_scaffold => true to your routes: by writing his in /config/routes.rb        
    map.resources :users, :active_scaffold :user
  8. rails s
  9. Open Browser: http://localhost:3000/teams
That ‘s it. You ve got a running application to CRUD teams and players using Rails 3 and ActiveScaffold.

No comments:

Post a Comment