Ruby on rails

From Null-pointer

(Redirected from Ruby on the rails)
Jump to: navigation, search

Contents

Creating a new rails application

[root@localhost ~]# rails [appName]

[root@localhost ~]# cd [appName]

[root@localhost [appName]]# ruby script/generate controller home index

Substrings

>> str = 'hello world'
=> "hello world"
 
>> str[6,5]
=> "world"
 
>> str[6..10]
=> "world"
 
>> str[6,1]
=> "w"
 
>> str[6..6]
=> "w"
 
>> str[6]
=> 119

BackTicks

This is one of the ways to execute shell commands

  1. def restartService(service)
  2.    begin
  3.      service_name = "/service/" + service
  4.      service_down = `svc -d #{service_name}`
  5.      service_up   = `svc -u #{service_name}`
  6.    rescue Exception => e
  7.    end
  8.  end

inline if statement

works

toggle ? "class='odd'" : ""

does not work

toggle?"class='odd'":""

Database config

config/database.yml

must have a "development" setting

rake db:migrate
rake db:migrate RAILS_ENV=production

debug

Unit test

[root@localhost my_ruby_project]# D:/devapps/Ruby/bin/ruby.exe -I"lib;test" \ "D:/devapps/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake/rake_test_loader.rb" \ "test/unit/my_ruby_object.rb"

Gems

update gems

[root@localhost ~]# gem install rubygems-update

[root@localhost ~]# gem update --system

install

[root@localhost ~]# gem install mysql

[root@localhost ~]# gem install mysql --version '> 2.7'

building rpms from ruby gems

See Also

Personal tools