Ruby on rails
From Null-pointer
(Redirected from Ruby on the rails)
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
- def restartService(service)
- begin
- service_name = "/service/" + service
- service_down = `svc -d #{service_name}`
- service_up = `svc -u #{service_name}`
- rescue Exception => e
- end
- 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'

