This is the short talk I delivered at the Ruby Underground Meetup in Tel Aviv for the local Ruby user group about some of the changes and new features in R
18. class Person < ActiveRecord::Base
attr_accessible :name, :age
validates_presence_of :name
validates_numericality_of :age
end
19. class Person < ActiveRecord::Base
attr_accessible :name, :age, :role
validates_presence_of :name
validates_numericality_of :age
validates_inclusion_of :role, in: %w(user admin)
end
20. class Person < ActiveRecord::Base
validates_presence_of :name
validates_numericality_of :age
validates_inclusion_of :role, in: %w(user admin)
end
21. class PeopleController < ActionController::Base
# ...
private
def person_params
params.require(:person).permit(:name, :age)
end
end
22. class PeopleController < ActionController::Base
def create
Person.create(params[:person])
end
# ActiveModel::ForbiddenAttributes
# ...
end
23. class PeopleController < ActionController::Base
def create
Person.create(person_params)
end
# ...
end
24. class PeopleController < ActionController::Base
# ...
def update
@person = current_account.people.find(params[:id])
redirect_to @person.tap { |person|
person.update_attributes!(person_params)
}
end
# ActionController::MissingParameter (400 Bad Request)
# ...
end
25. class PeopleController < ActionController::Base
# ...
private
def person_params
params.require(:person).permit(:name, :age)
end
end
class AdminController < ActionController::Base
# ...
private
def person_params
params.require(:person).permit(:name, :age, :role)
end
end
26. Page and Action Caching
Active Record Mass Assignment
Sanitizer
Active Record Session Store
Active Resource