The examples that follow assume that you are able to login to the VPS using SSH, and are comfortable working from the command line using standard Linux commands, and can edit files in the vi text editor. You cannot use the Control Panel to set up Ruby on Rails applications in the eApps Hosting service. |
[webadmin@example]$ cd /home/webadmin/example.com/html [webadmin@example html]$ rails hello create create app/controllers create app/helpers create app/models ....(more output) [webadmin@example html]$ [webadmin@example html]$ cd hello/ [webadmin@example hello]$ ruby script/generate controller hello exists app/controllers/ exists app/helpers/ .....(more output) [webadmin@example hello]$ [webadmin@example hello]$ cd app/controllers/ [webadmin@example controllers]$ vi hello_controller.rb |
class HelloController < ApplicationController end |
class HelloController < ApplicationController def index render :text => "hello world" end end |
[webadmin@example controllers]$ cd ../../config/ [webadmin@example config]$ pwd /home/webadmin/example.com/html/hello/config [webadmin@example config]$ vi routes.rb |
map.connect ':controller/:action/:id' map.connect ':controller/:action/:id.:format' end |
map.connect ':controller/:action/:id' map.connect ':controller/:action/:id.:format' map.connect '', :controller => "hello" end |
[webadmin@example config]$ vi environment.rb |
# config.frameworks -= [ :active_record, :active_resource, :action_mailer ] |
[webadmin@example config]$ cd initializers/ [webadmin@example initializers]$ vi new_rails_defaults.rb |
ActiveRecord::Base.store_full_sti_class = true |
[webadmin@example initializers]$ cd ../../public/ [webadmin@example public]$ pwd /home/webadmin/example.com/html/hello/public [webadmin@example public]$ mv index.html{,.bck} |
[webadmin@example public]$ cd .. [webadmin@example hello]$ pwd /home/webadmin/example.com/html/hello [webadmin@example hello]$ ruby script/server webrick -p 8000 => Booting WEBrick => Rails 2.3.4 application starting on http://0.0.0.0:8000 => Call with -d to detach => Ctrl-C to shutdown server [2009-10-13 13:33:11] INFO WEBrick 1.3.1 [2009-10-13 13:33:11] INFO ruby 1.8.6 (2008-08-11) [i386-linux] [2009-10-13 13:33:11] INFO WEBrick::HTTPServer#start: pid=23759 port=8000 |
[2009-10-13 13:59:30] INFO going to shutdown ... [2009-10-13 13:59:30] INFO WEBrick::HTTPServer#start done. Exiting [webadmin@example hello]$ |
A database and database user must be created before starting this example |
[webadmin@example] $ cd /home/webadmin/example.com/html [webadmin@example html]$ rails --database mysql helloWorld create
[webadmin@example html]$create app/controllers create app/helpers create app/models ~ ~ create log/server.log create log/production.log create log/development.log create log/test.log [webadmin@example html]$ cd helloWorld/config/ [webadmin@example config]$ vi database.yml |
~ ~ development: adapter: mysql encoding: utf8 reconnect: false database: helloWorld_test pool: 5 username: root password: socket: /var/lib/mysql/mysql.sock |
~ ~ development: adapter: mysql encoding: utf8 reconnect: false database: ror_test pool: 5 username: ror_user password: passwd socket: /var/lib/mysql/mysql.sock |
[webadmin@example config]$ cd .. [webadmin@example helloWorld]$ pwd /home/webadmin/example.com/html/helloWorld [webadmin@example helloWorld]$ ruby script/server => Booting Mongrel => Rails 2.3.4 application starting on http://0.0.0.0:3000 => Call with -d to detach => Ctrl-C to shutdown server |
[webadmin@example helloWorld]$ ruby script/generate controller say helloworld exists app/controllers/ exists app/helpers/ create app/views/say exists test/functional/ create test/unit/helpers/ create app/controllers/say_controller.rb create test/functional/say_controller_test.rb create app/helpers/say_helper.rb create test/unit/helpers/say_helper_test.rb create app/views/say/helloworld.html.erb [webadmin@example helloWorld]$ [webadmin@example helloWorld]$ cd app/controllers/ [webadmin@example controllers]$ vi say_controller.rb |
class SayController < ApplicationController def helloworld end end |
class SayController < ApplicationController def helloworld @HelloWorld = "Hello world" end end |
[webadmin@example controllers]$ cd ../views/say/ [webadmin@example views]$ pwd /home/webadmin/example.com/html/helloWorld/app/views/say/ [webadmin@example say]$ vi helloworld.html.erb |
<h1>Say#helloworld</h1> <p>Find me in app/views/say/helloworld.html.erb</p> |
<h1><%= @HelloWorld %></h1> |
[webadmin@example helloWorld]$ ruby script/generate scaffold greeting message:string exists app/models/ exists app/controllers/ exists app/helpers/ ~ ~ create test/fixtures/greetings.yml create db/migrate create db/migrate/20091021144316_create_greetings.rb [webadmin@example helloWorld]$ |
[webadmin@example helloWorld]$ rake db:migrate (in /home/webadmin/example.com/html/helloWorld) == CreateGreetings: migrating ================================================ -- create_table(:greetings) -> 0.0032s == CreateGreetings: migrated (0.0033s) ======================================= [webadmin@example helloWorld]$ |
[webadmin@example helloWorld]$ cd app/controllers/ [webadmin@example controllers]$ vi say_controller.rb |
class SayController < ApplicationController def helloworld @HelloWorld = "Hello world" end end |
class SayController < ApplicationController def helloworld @HelloWorld = Greeting.find(:last).message end end |
mod_rails is the recommended approach for deploying your Ruby on Rails applications on the eApps service |
Ruby Gems will also allow you to update the Ruby on Rails application service itself. DO NOT DO THIS!!
If you install an updated version of Ruby on Rails or any component of the application service using RubyGems, you will be outside of the eApps Support guidelines, and any assistance with Ruby on Rails will become billable at $15 per 10 minute increment. |
[webadmin@example ~]$ gem list --local *** LOCAL GEMS *** actionmailer (2.3.4) actionpack (2.3.4) actionwebservice (1.2.6) activerecord (2.3.4) activeresource (2.3.4) activesupport (2.3.4) cgi_multipart_eof_fix (2.5.0) daemons (1.0.10) fastthread (1.0.6) gem_plugin (0.2.3) mongrel (1.1.5) rack (1.0.0) rails (2.3.4) rake (0.8.4) |
[webadmin@example ~]$ gem list --remote > gem.txt [webadmin@example ~]$ cat gem.txt | wc -l 5404 [webadmin@example ~]$ more gem.txt aalib-ruby (0.7.1) aargvark (0.0.15) abn (1.3.0) AbsoluteRenamer (1.0.4, 1.0.3, 1.0.2, 1.0.1) abstract (1.0.0) ~ ~ ~ zsff (1.0.0) zvent (0.0.3) zyps (0.7.6) [webadmin@example ~]$ |
[root@example ~]# gem install yoda Successfully installed yoda-1.0.0 1 gem installed Installing ri documentation for yoda-1.0.0... Installing RDoc documentation for yoda-1.0.0... [root@example ~]# gem list --local *** LOCAL GEMS *** actionmailer (2.3.4) actionpack (2.3.4) actionwebservice (1.2.6) activerecord (2.3.4) activeresource (2.3.4) activesupport (2.3.4) cgi_multipart_eof_fix (2.5.0) daemons (1.0.10) fastthread (1.0.6) gem_plugin (0.2.3) mongrel (1.1.5) mongrel_cluster (1.0.5) rack (1.0.0) rails (2.3.4) rake (0.8.4) yoda (1.0.0) < -- here is the new gem [root@example ~]# |
[root@example ~]# gem server Starting gem server on http://localhost:8808/ (you will need to use Cntrl + c to stop the gem server) |
[root@example ~]# gem update yoda Updating RubyGems... ERROR: While executing gem ... (NoMethodError) undefined method efresh' for #<Hash:0xb794cd1c> [root@example ~]# rm -f /usr/lib/ruby/gems/1.8/source_cache [root@example ~]# gem update yoda Bulk updating Gem source index for: http://gems.rubyforge.org Successfully installed yoda-1.0.0 |