Hobo’s Miscellaneous Controller Extensions

This chapter of the Hobo Manual describes Hobo’s controller extensions.


Authentication support


This method checks if the user is authorized. It returns true by default. Override this method in your controllers if you want to restrict access to only a few actions or if you want to check if the user has the correct rights.


  # only allow nonbobs
  def authorized?
    current_user.login != "bob"


This is used as a filter to control authentication.

To require logins for all actions, use this in your controllers:

before_filter :login_required

To require logins for specific actions, use this in your controllers:

before_filter :login_required, :only => [ :edit, :update ]

To skip this in a subclassed controller:

skip_before_filter :login_required


Store the URI of the current request in the session. We can return to this location by calling #redirect_back_or_default.


Redirect to the URI stored by the most recent store_location call or to the passed default.

login_from_cookie and authenticated_user_from_cookie

When called with before_filter, login_from_cookie will call authenticated_user_from_cookie to check for an auth_token cookie, and if the result is appropiate, it will log the user in.

See the controller section in Users and Authentication for more information


Populates cookies[:auth_token] with current_user data.

See also the Hobo User Controller section in the Users and Authentication manual.


expire_swept_caches_for(obj, attr=nil)

This method is to be used in the controller as a partner to the <swept-cache> tag. Refer to the <swept-cache> taglib for more information.


Introduction to the Hobo Model Controller Module

Adding hobo_model_controller to one of your controllers will include this module

This module uses def included(base) to run some code in the context of the current controller. Some interesting stuff: * Defines @auto_actions as an empty hash if it’s not already defined. * Runs extend ClassMethods to add the ClassMethods module to the current controller. * Adds a couple of helpers: :model, :current_user * Rescues from some errors: ActiveRecord::RecordNotFound, ActiveRecord::RecordNotFound, Hobo::Model::Lifecycles::LifecycleKeyError * Loads some subsite magic

Class Methods

model_name and model

model_name returns model.name.underscore

model returns @model or controller_name.camelcase.singularize.constantize


This is the action called by the <name-one> tag to autocomplete results. See Autocompleters section in the controller manual.


See Web methods in the Controller manual.


See Selecting the automatic actions in the Controller manual.


See Lifecycles in the Controller manual.

Instance Methods


If your model is Foo, this method is equivalent to


in the simple case. However, it also understands owned routes and sets acting_user.

@foo = find_instance

is quite frequently the first line a custom Hobo controller action.


If you have errors on your page, you can call this helper to re-render the view that contains the source form, with errors highlighted.


Contains the logic for Automatic Redirects.


Converts params[:sort] from the form used by <table-plus> into a form suitable to be passed to the order_by scope.

Simple usage is to pass a list of field names, however the last parameter can be a hash which maps from field name to database column name.

parse_sort_param(:title, :isbn, :author => "authors.last_name")

parse_sort_param accepts dotted field names, automatically pluralizing to determine the database column.


will sort on task.title as long as :tasks is included or joined to the scope

Edit this page