Hobo’s Miscellaneous Controller Extensions
This chapter of the Hobo Manual describes Hobo’s controller extensions.
- Authentication support
doctest: prepare testapp environment doctest_require: ‘../prepare_testapp’
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" end
This is used as a filter to control authentication.
To require logins for all actions, use this in your controllers:
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:
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
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
See also the Hobo User Controller section in the Users and Authentication manual.
Introduction to the Hobo Model Controller Module
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.
extend ClassMethods to add the ClassMethods module to the current controller.
* Adds a couple of helpers:
* Rescues from some errors:
ActiveRecord::RecordNotFound, ActiveRecord::RecordNotFound, Hobo::Model::Lifecycles::LifecycleKeyError
* Loads some subsite magic
model_name and model
See Web methods in the Controller manual.
See Selecting the automatic actions in the Controller manual.
See Lifecycles in the Controller manual.
If your model is Foo, this method is equivalent to
in the simple case. However, it also understands owned routes and sets
@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.
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