Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Ams.rb Rails 4 Reality Bites

Ams.rb Rails 4 Reality Bites

My Ams.rb slides from 19/03/2013

Avatar for Nikolay Petrachkov

Nikolay Petrachkov

March 19, 2013

Other Decks in Programming

Transcript

  1. About • @ Quintel Intelligence • MSc Business Information Systems

    @ TU Eindhoven • Diemen resident, yo! 2 Wednesday, March 20, 13
  2. Prerequisites • Ruby 2.0.0-p0 • Mac OS X 10.7.5 •

    Rails 3.2 app 6 Wednesday, March 20, 13
  3. Gemfile Update more gems • gem 'sass-rails', ‘4.0.0.beta1’ • gem

    'coffee-rails', ‘4.0.0.beta1’ 9 Wednesday, March 20, 13
  4. Strong Parameters class Group < ActiveRecord::Base attr_accessible :description, :name, :users

    class GroupsController < ApplicationController ............. private def group_params params.require(:group).permit(:description, :name, :users) end end Rails 3 Rails 4 14 Wednesday, March 20, 13
  5. • (:users) was a string. • What if it is

    an array? 16 Wednesday, March 20, 13
  6. class Answer < ActiveRecord::Base belongs_to :question end class Question <

    ActiveRecord::Base belongs_to :survey has_many :answers accepts_nested_attributes_for :answers, allow_destroy: true end class Survey < ActiveRecord::Base has_many :questions accepts_nested_attributes_for :questions, allow_destroy: true end the example is based on Railscasts #196 19 Wednesday, March 20, 13
  7. class SurveysController < ApplicationController ......... private def survey_params params.require(:survey).permit(:name, questions_attributes:

    [ :content, :_destroy, :id, answers_attributes: [:content, :_destroy, :id] ] ) end end 21 Wednesday, March 20, 13
  8. Route Matching • root "home#index" • match "/dashboard" => "home#dashboard",

    as: :dashboard, via: :get • get "/about" => "home#about", as: :about Rails 4 23 Wednesday, March 20, 13
  9. Rails Eager Loading in config/environments/*.rb new options: • config.eager_load •

    config.eager_load_namespaces 24 Wednesday, March 20, 13
  10. config.eager_load • true or false • Controls the loading of

    the whole application into memory. • config.cache_classes = true Rails 3 25 Wednesday, March 20, 13
  11. Heroku • Add to your Gemfile • ruby ‘2.0.0’ •

    Success!! 31 Wednesday, March 20, 13
  12. Conclusion • Avoid using dynamic finders. Use where. • Add

    lambdas to scopes. • Strong parameters can be used in Rails 3 via gem. • Prepare for Rails 4! 32 Wednesday, March 20, 13
  13. Resources • Devise + Strong parameters: • http://bit.ly/devise4 • Rails

    4 mind map: • http://bit.ly/ror4map 33 Wednesday, March 20, 13