I got tired of typing the same commands all the time and/or looking up urls for plugins. Hence this script…. Yes, I know it’s been done before, but this does what I want (for now; I’m sure I’ll edit it).
It does the following:
- Creates rails instance (optionally setting the database, etc.)
- Installs rspec & rspec-rails
- Installs acts_as_statemachine
- Installs restful_authentication
- Modifies routes.rb
- Adds an observer
- Adds email settings
You can see the script below the cut or download it here:start-rails
(Edit: Removed an un-escaped pair of parens)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
#!/bin/ksh # start-rails # does the grunt work of starting a rails installation # By Matt Williams, http://matthewkwilliams.com # 25 Aug 2008 # # Released under MIT license if [ $# -lt 1 ]; then echo "Usage: ${0} project-name [rails arguments]" exit 1 fi project=$1 shift rails $* $project cd $project echo Set up rspec script/plugin install git://github.com/dchelimsky/rspec.git script/plugin install git://github.com/dchelimsky/rspec-rails.git script/generate rspec echo Install acts_as_statemachine script/plugin install http://elitists.textdriven.com/svn/plugins/acts_as_state_machine/trunk acts_as_state_machine echo Install restful auth script/plugin install git://github.com/technoweenie/restful-authentication.git script/generate authenticated user sessions --include-activation --stateful --rspec echo Database setup rake db:migrate rake db:migrate RAILS_ENV=test echo Add Activation route head -1 config/routes.rb > /tmp/start-rails-router.$$ cat <> /tmp/start-rails-router.$$ # Activation code map.activate '/activate/:activation_code', :controller => 'users', :action => 'activate', :activation_code => nil EOF size=`wc -l config/routes.rb` size=`expr ${size%% *} - 1` tail -${size} config/routes.rb >> /tmp/start-rails-router.$$ echo Updating user Route sed -e 's/map.resources :users.*$/map.resources :users, :member => { :suspend =>:put,:unsuspend =>:put,:purge =>:delete }/' /tmp/start-rails-router.$$ > config/routes.rb echo Adding Observer to config/environment.rb sed -e 's/# Activate observers.*/&\n\n config.active_record.observers = :user_observer\n/' config/environment.rb > /tmp/srfoo.$$ mv /tmp/srfoo.$$ config/environment.rb echo Setting globals cat >> config/environments/development.rb <> config/environments/production.rb <> config/environments/test.rb < /tmp/srfoo.$$ mv /tmp/srfoo.$$ app/models/user_mailer.rb echo Setting up the email initializer echo You will want to change the settings cat > config/initializers/email.rb < "mail.example-domain.com", :port => 25, :domain => "www.example-domain.com", :authentication => :login, :user_name => "user@example-domain.com", :password => "secret" } EOF echo Removing public/index.html rm public/index.html |
1 comment
Navjeet
September 10, 2008 at 11:54 am (UTC -5) Link to this comment
Installed a rails (using Rails 2.1.1) project with this script and now when I run script/server I get an error:
/usr/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/dependencies.rb:116:in `qualified_const_defined?’: “Plugins::Restful-authentication::Lib” is not a valid constant name! (NameError)
I read at http://agilewebdevelopment.com/plugins/restful_authentication somebody ran into same issue with Rails 2.1.0 but monkey patched Rails. A better solution is to rename vendor/plugin/restful-authentication folder to vendor/plugin/restful_authentication (use underscore). May be you can incorporate the renaming of folder in your script.