1.9 and faster ! Rails 4.0.1 Bug fixes + Active Record method order restored Let's go ! BEFORE WE START $ gem install rails Successfully installed rails-4.0.1 1 gem installed
match '/mosquitos/:id/kill', to: 'mosquitos#kill' post '/mosquitos/:id/kill', to: 'mosquitos#kill ' match '/mosquitos/:id/kill', to: 'mosquitos#kill', via: :post match '/mosquitos/:id/kill', to: 'mosquitos#kill', via: :all Rails 3 Rails 4
/mosquitos(.:format) mosquitos#create new_mosquito GET /mosquitos/new(.:format) mosquitos#new edit_mosquito GET /mosquitos/:id/edit(.:format) mosquitos#edit mosquito GET /mosquitos/:id(.:format) mosquitos#show PUT /mosquitos/:id(.:format) mosquitos#update PATCH /mosquitos/:id(.:format) mosquitos#update DELETE /mosquitos/:id(.:format) mosquitos#destroy PATCH, http 1.1(modify an existing HTTP resource) Rails 4 Added in forms helpers and tests.
resources :tasks do resources :comments end resources :milestone do resources :comments end end Without concerns... With concerns, much more DRY AnnoyingApp::Application.routes.draw do # options can be added to concerns concern :commentable do resources :comments end resources :projects, concerns: :commentable resources :tasks, concerns: :commentable resources :milestone, concerns: :commentable end
a scope #<ActiveRecord::Relation []> Insect.all #<ActiveRecord::Relation [#<Insect id: 1, name : 'Mosquito'...>, ...]> none all Insect.where.not(kind: 'Crawling') # generate better SQL syntax not These methods now return an ActiveRecord::Relation
class Insect < ActiveRecord::Base end Rails 4 (controller is now responsible for whitelisting parameters) def create @insect = Insect.new(insect_params) # ... end def update @insect.update(insect_params) # ... end private def insect_params params.require(:insect).permit(:name,:kind,:sound) end class Insect < ActiveRecord::Base attr_accessible :name,:kind,:sound end # You can still use this in Rails 4 with gem 'protected_attributes'
= '637fe3fc6ee1fc23e...' # I should get that in an environment variable Rails 4 now they're not (in config/initializers/secret_token.rb) cookie = "BAh7CUkiD3Nlc3Npb25faWQGOgZFRkkiJ..." Rack::Session::Cookie::Base64::Marshal.new.decode(cookie) => { "session_id" => "0ba43a95f93e91538...", "user_id" => "42", "_csrf_token" => "xdpFHDeEeuVlRD9mIBW/tFcKI..." }
:name, :kind, :sound json.url insect_url(insect, format: :json) end Now you can customize the json response easily # app/views/insects/index.json.ruby insects_hashes = @insects.map do |insect| { name: insect.name, kind: insect.kind, url: insect_url(insect) } end insects_hashes.to_json Or in plain ruby # in app/views/insects/index.json.jbuilder json.array!(@insects) do |insect| json.extract! insect, :name, :kind, :sound json.url insect_url(insect, format: :json) end Now you can customize the json response easily # app/views/insects/index.json.jbuilder json.array!(@insects) do |insect| json.extract! insect, :name, :kind, :sound json.url insect_url(insect, format: :json) end Now you can customize the json response easily
Present in Rails 4 $(document).ready(init); $(document).on('page:fetch'); # or better $(document).on('click', '#myElement', myAction); # or even gem 'jquery.turbolinks' //= require jquery.turbolinks Beware of your code, it could be not ran