HOWTO RoR
From Gentoo Linux Wiki
|
|
|
Main Modules
Addons & Tunnels
Tips Configuring Other |
| edit |
This HOWTO demostrates to users how to install Ruby on Rails 1.1 on Gentoo, with Apache2 and SQLite, with some notes about using RoR 1.2.x.
[edit] Setting up Ruby On Rails 1.1
Since FastCGI and SQLite will be used, fastcgi and sqlite3 should be added into the use flag.
# nano /etc/make.conf USE="(existing use flags here) fastcgi sqlite3"
Now, rubyonrails is ready to be installed.
| Code: Emerge rails |
# emerge -av rails mod_fcgid swig # gem install fcgi |
If "gem install fcgi" fails simply try again, it might work this time.
After the rails is installed on the computer, it should be tested before integrating with Apache2 or SQLite.
Firstly, we should create the test application:
| Code: Create test application |
# cd /var/www/localhost # rails test |
and make sure the public and tmp folders are accessible by apache2 (they should be owned by apache:apache).
| Code: Ensure proper permission |
# cd /var/www/localhost/test # chown -R apache:apache public tmp # mkdir /var/www/localhost/fcgi-log # chown -R apache:apache /var/www/localhost/fcgi-log |
Since it is a good idea to log failure, we will modify the last line of dispatch.fcgi under the test/public directory so that it looks similar to this:
| Code: /var/www/localhost/test/public/dispatch.fcgi |
RailsFCGIHandler.process! '/var/www/localhost/fcgi-log/test_fcgi_crash.log' |
test/public/.htaccess should also be modified to use fastcgi as well by making the following changes:
| Code: /var/www/localhost/test/public/.htaccess |
- AddHandler fastcgi-script .fcgi + AddHandler fcgid-script .fcgi - RewriteRule ^(.*)$ dispatch.cgi [QSA,L] + RewriteRule ^(.*)$ dispatch.fcgi [QSA,L] |
The test application does not use database, so there is no need to edit test/config/database.yml.
The test application can now be tested with the built in web server, WEBrick. Make sure the following command is executed in the test folder.
| Code: Testing test application |
# cd /var/www/localhost/test # ruby ./script/server -e test |
Open the site http://localhost:3000 with your favourite web browser. You should see the welcome aboard page. Click on the "About your application’s environment" link to check that rails is indeed working. If you have troubles running it, such as encountering the "no route found to match "/rails/info/properties" with {:method=>:get}" error, try it this way:
| Code: Testing test application |
# script/server |
Run the following command as well
| Code: Testing controller |
# script/generate controller home |
and go to http://localhost:3000/home to ensure rails controller works. You should get a dispatch error.
Now that ruby on rails is working, we should set up the application to use SQLite.
[edit] Installing SQLite
Since emerge has already installed sqlite along with rails, we only need to install the SQLite gem.
| Code: install sqlite3-ruby |
emerge -av sqlite3-ruby gem install sqlite3-ruby |
Select sqlite3-ruby 1.1.0 (ruby) when prompted.
SQLite stores database into individual files. To create a database with SQLite (version 3), the following command will suffice.
| Code: create database |
# sqlite3 db/test.db < /path/to/schema.sql |
And modify config/database.yml so that the application will use SQLite:
| Code: /var/www/localhost/test/config/database.yml |
development: adapter: sqlite3 dbfile: db/dev.db test: adapter: sqlite3 dbfile: db/test.db production: adapter: sqlite3 dbfile: db/prod.db |
If you are using older version of SQLite, put sqlite as adapter instead.
[edit] Setting up Apache2 for Rails Applications
Edit /etc/conf.d/apache2 so that fastcgi will be loaded:
APACHE2_OPTS="-D DEFAULT_VHOST -D SSL -D SSL_DEFAULT_VHOST -D FCGID"
The rewrite modules included with Apache2 may be needed. Therefore, make sure the following is added to /etc/apache2/httpd.conf (assuming this is the location for apache's configuration file)
| Code: /etc/apache2/httpd.conf |
LoadModule rewrite_module modules/mod_rewrite.so #LoadModule fcgid_module modules/mod_fcgid.so <Directory /var/www/localhost/> AllowOverride all </Directory> <IfModule mod_fastcgi.c> FastCgiIpcDir /tmp/fcgi_ipc/ # AddHandler fastcgi-script .fcgi AddHandler fcgid-script .fcgi </IfModule> #You may need to uncomment this line: Include /etc/apache2/vhosts.d/*.conf |
Make sure the /tmp/fcgi_ipc directory is accessible by all:
| Code: setting permission |
# mkdir /tmp/fcgi_ipc # chmod 777 /tmp/fcgi_ipc |
As seen in /etc/apache2/modules.d/20_mod_fcgid.conf, the same operation should be done for directory /var/run/fcgidsock and file /var/run/fcgid_shm:
The following should be added into /etc/apache2/vhosts.d/00_default_vhost.conf
| Code: /etc/apache2/vhosts.d/00_default_vhost.conf |
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin webmaster@example.com
DocumentRoot /var/www/localhost/test/public
ServerName www.example.com
ErrorLog /var/log/apache2/test-error_log
CustomLog /var/log/apache2/test-access_log common
<Directory /var/www/localhost/test/public>
Allow from all
AllowOverride all
Order allow,deny
</Directory>
Options Indexes ExecCGI FollowSymLinks
RewriteEngine On
</VirtualHost>
|
To view your rails app go to http://www.example.com/home (make sure the proper DNS is set up). If you are greeted with an application error, you probably need to change the permissions for your rails directory:
chown [APACHE USER] -R /var/www/localhost/test chmod g+w -R /var/www/localhost/test
substitute the apache user for [APACHE USER] (probably "www-data" or "apache").
[edit] Rake warnings
If script/server spews warnings that look like the following then you've got conflicting versions of modules installed. This usually happens if you run "gem update" after you've emerged rails.
# script/server => Booting lighttpd (use 'script/server webrick' to force WEBrick) => config/lighttpd.conf not found, copying from /usr/lib/ruby/gems/1.8/gems/rails-1.1.2/configs/lighttpd.conf => Rails application started on http://0.0.0.0:3000 => Call with -d to detach => Ctrl-C to shutdown server (see config/lighttpd.conf for options) /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/validations.rb:334: warning: `*' interpreted as argument prefix /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/validations.rb:363: warning: `*' interpreted as argument prefix /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/migration.rb:224: warning: instance variable @ignore_new_methods not initialized /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/migration.rb:224: warning: instance variable @ignore_new_methods not initialized /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/connection_adapters/abstract/connection_specification.rb:41: warning: method redefined; discarding old allow_concurrency= /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/connection_adapters/sqlserver_adapter.rb:456: warning: method redefined; discarding old remove_column /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/connection_adapters/oracle_adapter.rb:119: warning: (...) interpreted as grouped expression /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/request.rb:169: warning: method redefined; discarding old relative_url_root /usr/lib/ruby/1.8/cgi/session/pstore.rb:17: warning: method redefined; discarding old []= /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/cgi_ext/raw_post_data_fix.rb:57: warning: ambiguous first argument; put parentheses or even spaces /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/cgi_ext/raw_post_data_fix.rb:8: warning: method redefined; discarding old initialize_query /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/session/active_record_store.rb:129: warning: private attribute? /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/session/active_record_store.rb:179: warning: method redefined; discarding old connection /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_view/helpers/prototype_helper.rb:640: warning: ambiguous first argument; put parentheses or even spaces /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_view/helpers/prototype_helper.rb:873: warning: `*' interpreted as argument prefix /usr/lib/ruby/gems/1.8/gems/actionmailer-1.2.1/lib/action_mailer/vendor/tmail/facade.rb:486: warning: method redefined; discarding old create_reply /usr/lib/ruby/gems/1.8/gems/actionwebservice-1.1.2/lib/action_web_service/protocol/xmlrpc_protocol.rb:6: warning: discarding old message /usr/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/initializer.rb:581: warning: method redefined; discarding old []= /usr/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/initializer.rb:590: warning: method redefined; discarding old [] /usr/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/initializer.rb:595: warning: method redefined; discarding old keys /usr/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/initializer.rb:600: warning: method redefined; discarding old find_pair /usr/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/initializer.rb:607: warning: method redefined; discarding old []= /usr/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/initializer.rb:611: warning: method redefined; discarding old [] /usr/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/initializer.rb:615: warning: method redefined; discarding old method_missing Exiting /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/validations.rb:334: warning: `*' interpreted as argument prefix /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/validations.rb:363: warning: `*' interpreted as argument prefix /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/migration.rb:224: warning: instance variable @ignore_new_methods not initialized /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/migration.rb:224: warning: instance variable @ignore_new_methods not initialized /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/connection_adapters/abstract/connection_specification.rb:41: warning: method redefined; discarding old allow_concurrency= /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/connection_adapters/sqlserver_adapter.rb:456: warning: method redefined; discarding old remove_column /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/connection_adapters/oracle_adapter.rb:119: warning: (...) interpreted as grouped expression /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/request.rb:169: warning: method redefined; discarding old relative_url_root /usr/lib/ruby/1.8/cgi/session/pstore.rb:17: warning: method redefined; discarding old []= /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/cgi_ext/raw_post_data_fix.rb:57: warning: ambiguous first argument; put parentheses or even spaces /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/cgi_ext/raw_post_data_fix.rb:8: warning: method redefined; discarding old initialize_query /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/session/active_record_store.rb:129: warning: private attribute? /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/session/active_record_store.rb:179: warning: method redefined; discarding old connection /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_view/helpers/prototype_helper.rb:640: warning: ambiguous first argument; put parentheses or even spaces /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_view/helpers/prototype_helper.rb:873: warning: `*' interpreted as argument prefix /usr/lib/ruby/gems/1.8/gems/actionmailer-1.2.1/lib/action_mailer/vendor/tmail/facade.rb:486: warning: method redefined; discarding old create_reply /usr/lib/ruby/gems/1.8/gems/actionwebservice-1.1.2/lib/action_web_service/protocol/xmlrpc_protocol.rb:6: warning: discarding old message /usr/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/initializer.rb:581: warning: method redefined; discarding old []= /usr/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/initializer.rb:590: warning: method redefined; discarding old [] /usr/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/initializer.rb:595: warning: method redefined; discarding old keys /usr/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/initializer.rb:600: warning: method redefined; discarding old find_pair /usr/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/initializer.rb:607: warning: method redefined; discarding old []= /usr/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/initializer.rb:611: warning: method redefined; discarding old [] /usr/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/initializer.rb:615: warning: method redefined; discarding old method_missing
I fixed this by totally unmerging rails and all its dependent packages:
# emerge -av --unmerge actionpack actionwebservice activerecord activesupport actionmailer rake rails
and then relying on gem to manage rails:
# gem install rails
Obviously, you can go the other way and let portage manage the packages for you. In my case, rails was at 1.1.4 in RubyGems and 1.1.2 in portage, so that won out. Just make sure you never ever run gem update if you're letting portage manage rails for you.
If gem gives you: ERROR: While executing gem ... (Gem::GemNotFoundException)
This fixed it for me:
#rm /usr/lib/ruby/gems/1.8/source_cache #rm ~someuser/.gem/source_cache
And if that does not fix it, try:
# gem update
And then repeat the 'gem install' command you were trying.
[edit] Notes on using Rails 1.2.3
Previous hackery unnecessary now on ~x86 - just edit:
| Code: /etc/portage/package.keywords |
dev-ruby/rubygems ~x86 dev-ruby/rails ~x86 dev-ruby/rake ~x86 dev-ruby/actionwebservice ~x86 dev-ruby/actionpack ~x86 dev-ruby/activesupport ~x86 dev-ruby/activerecord ~x86 dev-ruby/actionmailer ~x86 |
Then emerge rails.
I'm experimenting with adding 'dev-lang/ruby ~x86' to package.keywords also.
- Thomas - http://www.railfrog.com/ - Simple Rails CMS
