Class ApplicationController < ActionController::Base

Base controller for every controller in Ecrire (Theme & Admin) Ecrire::ThemeController inherits from this class so there are no reason why you should inherit from this class.

The controller handles user authentication, and CSRF protection.

It also provides a url method to build complex URL using a very light syntax.

Instance Methods

  1. current_user()

    Return current signed user or nil, if the user is not signed in

  2. signed_in?()

    Returns true if the user is signed in

  3. url(path, options = {})

    Returns a URL based on the path and options provided. It does not try to validate the URL, it only generates it and assume it's a valid URL.

    path: The relative path of the URL you want to build.

    options: Hash containing options for rendering the url.

    The path and options are linked together via a mapping construct that you can use to map records to part of the URL.

    To map records to the path, you need to specify the record & the method you want to use inside the path.

    url('/admin/posts/:posts.id', post: @post)
    -> '/admin/posts/32'

    The method looks for every occurence of “:[key].” and will look in options for that key and call the given method on that key.

    This means the object can be anything as long as it handles the method.

    Here are a other examples:

    url('/users/:user.id/tags/:tag.id/', user: @user, tag: @tag)
    -> '/users/12/tags/12'
    
    url('/users')
    -> '/users'

    The options also looks for the absolute_path key. If it's set to true, the method will return an absolute path.

    url('/users/:user.id/tags/:tag.id/', user: @user, tag: @tag, absolute_path: true)
    -> 'http://localhost:3000/users/12/tags/12'
    
    url('/users', absolute_path: true)
    -> 'http://localhost:3000/users'