Child pages
  • Using Ruby on Rails 3.0.5 on O.I.

Versions Compared


  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 4.0
  1. Create a user account like "oi" and empower oi user to have package install right in /etc/user_attr.
    Code Block
    oi@openindiana:~/demo1$ grep oi /etc/user_attr
    oi::::profiles=Primary Administrator;=root
  2. Ruby-1.8.7 by default is not installed.  Run pkg install to install the package and gcc.
    Code Block
    oi@openindiana:~$ pkg install  pkg:/runtime/ruby-18 developer/gcc-3
  3. "gem update --system "d to get latest gem tool(1.7.2+). 
    1. If behind firewall, "gem update --http-proxy --system"
  4. Run "gem install rails -v 3.0.5" to install rails-3.0.5. This will install all the rails depended gems.
  5. Install sqlite3 so that we have a database backend for testing.
    1. "gem install sqlite3" will need gcc compiler installed.
  6. A quick check of installed Ruby stuff.
    Code Block
    oi@oi:~$ ruby -v
    ruby 1.8.7 (2009-06-12 patchlevel 174) [i386-solaris2.11]
    oi@oi:~$ gem -v
    oi@oi:~$ gem env
    RubyGems Environment:
      - RUBYGEMS VERSION: 1.7.2
      - RUBY VERSION: 1.8.7 (2009-06-12 patchlevel 174) [i386-solaris2.11]
      - INSTALLATION DIRECTORY: /var/ruby/1.8/gem_home
      - RUBY EXECUTABLE: /usr/ruby/1.8/bin/ruby
      - EXECUTABLE DIRECTORY: /var/ruby/1.8/gem_home/bin
        - ruby
        - x86-solaris-2.11
      - GEM PATHS:
         - /var/ruby/1.8/gem_home
         - /export/home/oi/.gem/ruby/1.8
         - /usr/ruby/1.8/lib/ruby/gems/1.8
         - :update_sources => true
         - :verbose => true
         - :benchmark => false
         - :backtrace => false
         - :bulk_threshold => 1000
    oi@oi:~/demo1$ rails -v
    Rails 3.0.5
    oi@oi:~$uname -a
    SunOS oi 5.11 oi_148 i86pc i386 i86pc
  7. Create a test rails app "demo1"
    Code Block
    oi@oi:~$ rails new demo1
          create  README
          create  Rakefile
          create  .gitignore
          create  Gemfile
          create  app
          create  app/controllers/application_controller.rb
          create  app/helpers/application_helper.rb
          create  config/environments/development.rb
          create  config/environments/production.rb
          create  config/environments/test.rb
          create  config/initializers
          create  config/initializers/backtrace_silencers.rb
          create  vendor/plugins
          create  vendor/plugins/.gitkeep
  8. Using rails to create user database table without sql commands.
    Code Block
    oi@oi:~/demo1$ rails generate scaffold User name:string email:string
          invoke  active_record
          create    db/migrate/20110402071401_create_users.rb
          create    app/models/user.rb
          invoke    test_unit
          create      test/unit/user_test.rb
          create      test/fixtures/users.yml
           route  resources :users
          invoke  scaffold_controller
          create    app/controllers/users_controller.rb
          invoke    erb
          create      app/views/users
          create      app/views/users/index.html.erb
          create      app/views/users/edit.html.erb
          create      app/views/users/show.html.erb
          create      app/views/users/new.html.erb
          create      app/views/users/_form.html.erb
          invoke    test_unit
          create      test/functional/users_controller_test.rb
          invoke    helper
          create      app/helpers/users_helper.rb
          invoke      test_unit
          create        test/unit/helpers/users_helper_test.rb
          invoke  stylesheets
          create    public/stylesheets/scaffold.css
    oi@oi:~/demo1$ rake db:migrate
    (in /home/tjyang/demo1)
    ==  CreateUsers: migrating ====================================================
    -- create_table(:users)
       -> 0.0020s
    ==  CreateUsers: migrated (0.0022s) ===========================================
  9. Verify user table really got created.
    Code Block
    oi@oi:~/demo1$ sqlite3 ./db/development.sqlite3
    SQLite version 3.6.23
    Enter ".help" for instructions
    Enter SQL statements terminated with a ";"
    sqlite> .tables
    schema_migrations  users
    sqlite> .exit
  10. Startup demo1 rails application
    Code Block
    oi@oi:~/demo1$ rails s
    => Booting WEBrick
    => Rails 3.0.5 application starting in development on
    => Call with -d to detach
    => Ctrl-C to shutdown server
    [2011-04-02 02:23:50] INFO  WEBrick 1.3.1
    [2011-04-02 02:23:50] INFO  ruby 1.8.7 (2009-06-12) [i386-solaris2.11]
    [2011-04-02 02:23:51] INFO  WEBrick::HTTPServer#start: pid=48 port=3000
    Started GET "/users" for at Sat Apr 02 02:25:53 -0500 2011
      Processing by UsersController#index as HTML
      User Load (1.0ms)  SELECT "users".* FROM "users"
    Rendered users/index.html.erb within layouts/application (4.3ms)
    Completed 200 OK in 58ms (Views: 11.0ms | ActiveRecord: 1.0ms)
    Started GET "/rails/info/properties" for at Sat Apr 02 02:27:06 -0500 2011
      Processing by Rails::InfoController#properties as
      SQL (0.5ms)   SELECT name
     FROM sqlite_master
     WHERE type = 'table' AND NOT name = 'sqlite_sequence'
      SQL (0.2ms)   SELECT name
     FROM sqlite_master
     WHERE type = 'table' AND NOT name = 'sqlite_sequence'
      SQL (0.1ms)  SELECT "schema_migrations"."version" FROM "schema_migrations"
    Rendered inline template (0.3ms)
    Completed 200 OK in 29ms (Views: 1.4ms | ActiveRecord: 0.8ms)
    Started GET "/users" for at Sat Apr 02 02:28:05 -0500 2011
      Processing by UsersController#index as HTML
      User Load (0.5ms)  SELECT "users".* FROM "users"
    Rendered users/index.html.erb within layouts/application (3.1ms)
    Completed 200 OK in 14ms (Views: 9.0ms | ActiveRecord: 0.5ms)
  11. See it from Chrome browser.
  12. See users listing
  13. Above procedure digitized into demo1.xml
    Code Block
    oi@openindiana:~$ cat demo1.xml
    <?xml version="1.0"?>
      <program name="rails" version="3.0.5" revision="1">
    case "${SB_SYSTYPE}" in
    # x86 OpenIndiana is currently shown as i386-pc-solaris-2.11.
    pfexec pkg install  pkg:/runtime/ruby-18 \
    # Need to specify gem 1.6.2 for now, 1.7.1 has issue.
    pfexec gem update --system  1.6.2
    pfexec gem install rails -v 3.0.5
    pfexec gem install sqlite3
    /var/ruby/1.8/gem_home/bin/rails new demo1
    cd demo1
    /var/ruby/1.8/gem_home/bin/rails generate scaffold User name:string email:string
    /var/ruby/1.8/gem_home/bin/rake db:migrate
    cd demo1
    /var/ruby/1.8/gem_home/bin/rails s
  14. Lets play it back by /opt/TWWfsw/bin/sb tool.
    Code Block
    oi@openindiana:~$ /opt/TWWfsw/bin/sb -uCBi demo1.xml
  15. References
    1. Ruby on Rails 3 tutorial
    2. Set up TWW sb on OI