1. 脚本命令
旧的命令 新的用法
script/generate rails g
script/console rails c
script/server rails s
script/dbconsole rails db
2. 配置文件
rails2: config/environment.rb
- Rails::Initializer.run do |config|
- config.load_paths += %W( #{RAILS_ROOT}/extras )
- config.gem "bj"
- config.gem "sqlite3-ruby" , :lib => "sqlite3"
- config.gem "aws-s3" , :lib => "aws/s3"
- config.plugins = [ :exception_notification ]
- config.time_zone = 'UTC'
- end
Rails::Initializer.run do |config|
config.load_paths += %W( #{RAILS_ROOT}/extras )
config.gem "bj"
config.gem "sqlite3-ruby", :lib => "sqlite3"
config.gem "aws-s3", :lib => "aws/s3"
config.plugins = [ :exception_notification ]
config.time_zone = 'UTC'
end
rails3:config/application.rb
- module APP_NAME
- class Application < Rails::Application
- config.load_paths += %W( #{RAILS_ROOT}/extras )
- config.plugins = [ :exception_notification ]
- config.time_zone = 'UTC'
- end
- end
module APP_NAME
class Application < Rails::Application
config.load_paths += %W( #{RAILS_ROOT}/extras )
config.plugins = [ :exception_notification ]
config.time_zone = 'UTC'
end
end
这样就变成了一种架构式的应用, 我们可以根据方便的对config进行操作
3. 路由
在rails3中, 已经的路由可以继续工作, 而新的路由方式更加简洁.
在 rails2 中:
- map.resources :posts do |post|
- post.resources :comments
- end
map.resources :posts do |post|
post.resources :comments
end
而在rails3中 , 表达更为形象:
- resources :posts do
- resources :comments
- end
resources :posts do
resources :comments
end
对于一些复杂的路由, rails2:
- post.resources :comments ,
- :member => { :preview => :post },
- :collection => { :archived => :get }
post.resources :comments,
:member => { :preview => :post },
:collection => { :archived => :get }
在 rails3中可以这样表达:
- resources :comments do
- member do
- post :preview
- end
- collection do
- get :archived
- end
- end
resources :comments do
member do
post :preview
end
collection do
get :archived
end
end
不够简洁? 我们还可以这样做:
- resources :comments do
- post :preview , :on => :member
- get :archived , :on => :collection
- end
resources :comments do
post :preview, :on => :member
get :archived, :on => :collection
end
对于基本路由, rails2:
- map.connect 'login' , :controller => 'session' , :action => 'new'
map.connect 'login', :controller => 'session', :action => 'new'
那么在rails3中:
- match <