class PeopleController < ApplicationController def create @person = Person.new(params[:person]) if @person.save redirect_to @person, notice: 'Person was successfully created.' else render action: 'new' end end end Rails 3 Wednesday, April 10, 13
loading of pages Uses javascript to reload just the body of a page instead of doing a full reload Watch out for js that executes on page load. Run that code by listening for the turbolinks “page:load” event. TURBOLINKS Wednesday, April 10, 13
for nested fragment cache calls Automatically adds a digest value to the cache key for the fragment based on the contents of the template and its dependencies (almost automatically) RUSSIAN DOLL CACHING Wednesday, April 10, 13
server that does not buffer output and can handle multiple connections (i.e. in development don’t use WEBrick - use thin or puma) Write to response.stream to send data immediately to the browser Close the stream when done ACTIONCONTROLLER::LIVE Wednesday, April 10, 13
hash as well as a string now .not negates a where clause .none returns an empty Relation that doesn’t hit the database .load causes the query to be executed, but returns a Relation .all returns a Relation instead of an Array (you can still use to_a) .all takes the place of the now deprecated .scoped ACTIVERECORD CHANGES Wednesday, April 10, 13
now supported natively Use hstores to store hashes. Keys and values are always stored as strings and must be type cast on the way out of the db The value of using these data types vs. just using a serialized column is in Postgres’ querying capabilities Use config.active_record.schema_format = :sql Wednesday, April 10, 13
a class to create a non- database-backed model (validations, callbacks, attributes, etc) Scopes always need to have a callable (lambda, proc, etc) as their second argument Wednesday, April 10, 13
m2m associations and arrays New date/time form helpers: e.g. date_field instead of date_select. Produces <input type=”date”> Ruby template handler Wednesday, April 10, 13
duplication in routes The match method is deprecated. Use get/post/put/ patch/delete instead Constraints turn into default attributes for url helpers Wednesday, April 10, 13