cone / r5kitchensink

Exploring Rails 5 in depth

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

README

Rack

Run rake middleware to see all rack filters.

Option for adding a new filter:

• config.middleware.insert_after(existing_middleware, new_middleware, args)—Adds the new middleware after the specified existing middleware in the middleware stack.

• config.middleware.insert_before(existing_middleware, new_middleware, args)—Adds the new middleware before the specified existing middleware in the middleware stack.

• config.middleware.delete(middleware)—Removes a specified middleware from the stack.

• config.middleware.swap(existing_middleware, new_middleware, args)—Swaps a specified middleware from the stack with a new class.

• config.middleware.use(new_middleware, args)—Takes a class reference as its parameter and just adds the desired middleware to the end of the middleware stack.

Make a request manually from Rails console:

>> env = {}
>> env['REMOTE_ADDR'] = '127.0.0.1'
>> env['REQUEST_METHOD'] = 'GET'
>> env['PATH_INFO'] = '/products/1'
>> env['rack.input'] = StringIO.new
>> rack_body_proxy = R5kitchensink::Application.call(env).last
>> rack_body_proxy.last

Format response as YAML:

>> y R5kitchensink::Application.call(env)

Misc

Include custom helper for using in console mode

Redirecting console output to STDOUT

Routing and resources

Simple routing examples

Simple resource creation for CRUD operations

Adding nested resources example

Example of route resource concerns

Add route customization example

Add collection routes example

Custom action names example

Map to a different controller example

Routes for new resources example

Respond to a specific format and show link with an extension

Controllers

Example of redirecting from controller More redirecting options

Example of rendering another template

Example of rendering partials

Example of rendering html

Example of rendering inline template code

Example of rendering plain and using a helper

Example of rendering Javascript

Example of rendering options

More rendering options

Example of rendering nothing

Example of changing the layout

Example of redirecting back

Example of setting callbacks on controller

Example of using prepend_before_action

Example of around_action

Example of skipping cllbacks

Models

Example of ActiveRecord table configurations

Example of adding a default value for a field directly on the model

Examples of model instance creation

Examples of finding records

Examples of accessing model instance attributes

About

Exploring Rails 5 in depth


Languages

Language:Ruby 80.7%Language:HTML 15.7%Language:JavaScript 2.2%Language:CSS 1.3%