An overview of some of the new features in Rails 4. All features are discussed in depth in the e-book Upgrade to Rails 4 (http://www.leanpub.com/upgradetorails4) as well.
25. RAILS 4
class CarsController < ApplicationController
def create
@car = Car.new(car_params)
if @car.save
redirect_to @car
else
render „new‟
end
end
end
26. private
def car_params
params.require(:car).permit(:name, :year, :brand)
end
require(key) - Ensures that a parameter is present. If it‟s present,
returns the parameter at the given key, otherwise raises an
ActionController:: ParameterMissing error.
permit(filters) - Returns a new ActionController::Parameters
instance that includes only the given filters
and sets the permitted attribute for the object to true. This is useful
for limiting which attributes should be allowed for mass updating.
41. class ContactsController < ApplicationController
def new
@contact = Contact.new
end
def create
@contact = Contact.new(params[:contact])
if @contact.valid?
UserMailer.new_contact(@contact).deliver
redirect_to root_path, notice: "Message sent! Thanks.”
else
render :new
end
end
end
42. LOTS OF OTHER STUFF
ROUTING CONCERNS THREAD SAFETY
CONTROLLER-WIDE E-TAGS ENCRYPTED COOKIES
HTTP PATCH VERB
CUSTOM FLASH TYPES
HTML5 FORM HELPERS
SCHEMA CACHE DUMP
PAGE/ACTION CACHING
NO MORE OBSERVERS/SWEEPERS
ACTIVE RESOURCE INDEX PAGE CONTROLLER