I give a run-down of some of the latest features in Rails slated for the 4.0 release, and tips on how to prepare your Rails 3 app for upcoming changes.
Person.create(person_params) end private def person_params params.require(:person).permit(:name, :age) end end Use in Rails 3 Today: https://github.com/rails/strong_parameters In Rails 4: Thursday, February 7, 13
action code must be thread save! • Concurrent Ruby Server Required (puma, rainbows!, thin) • Headers must be written before anything else • Streams must be closed http://tenderlovemaking.com/2012/07/30/is-it-live.html Thursday, February 7, 13
:articles do |t| t.string :tags, array: true end end end article.tags = ['rails'] article.save # UPDATE "articles" SET "tags" = '{"rails"}' # WHERE "articles"."id" = 1 HStore Support New Data Types Support Thursday, February 7, 13
'Rails 5']) Article.where("title != ?", "Rails 3") Article.where("title NOT IN (?)", ["Rails 3", "Rails 5"]) In Rails 3: In Rails 4: Thursday, February 7, 13
role if 'Country Manager' Post.where(:country => country) if 'Reviewer' Post.published if 'Bad User' # returning [] instead breaks the previous code; not chainable Post.where("1=0") end end In Rails 3: Thursday, February 7, 13
role if 'Country Manager' Post.where(:country => country) if 'Reviewer' Post.published if 'Bad User' # returning [] instead breaks the previous code; not chainable Post.none end end In Rails 4: Thursday, February 7, 13
= People.active @people = @people.where(:first_name => params[:first_name]) if params[:last_name].present? @people = @people.where(:last_name => params[:last_name]) if params[:last_name].present? end end In Rails 3: Thursday, February 7, 13
= People.active @people.where!(:first_name => params[:first_name]) if params[:last_name].present? @people.where!(:last_name => params[:last_name]) if params[:last_name].present? end end In Rails 4: Thursday, February 7, 13
My todolist: <%= todolist.name %> <%= render document.comments %> <% end %> # app/views/comments/_comment.html.erb <% cache comment do %> My comment: <%= comment.body %> <% end %> In Rails 3: Thursday, February 7, 13
] do %> My todolist: <%= todolist.name %> <%= render document.comments %> <% end %> # app/views/comments/_comment.html.erb <% cache [ "v1", comment ] do %> My comment: <%= comment.body %> <% end %> In Rails 3: Thursday, February 7, 13
My todolist: <%= todolist.name %> <%= render document.comments %> <% end %> # app/views/comments/_comment.html.erb <% cache comment do %> My comment: <%= comment.body %> <% end %> In Rails 4: Thursday, February 7, 13
partial update, what everyone is using PUT for today. Default for update will now be PATCH. https://github.com/rails/rails/pull/505 Thursday, February 7, 13