# Shortcut for :unprocessable_entity, head(:failed) instead of head(:unprocessable_entity) ActionController::StatusCodes::SYMBOL_TO_STATUS_CODE[:failed] = 422 # # url_for, used to generate url_for for string path with options and with default_url_options # ActionController::Base.class_eval do protected # # Bunch of small actions # def render_action action_or_template args = action_or_template.to_s.split('/') args.size.should! :be_in, 1..2 if args.size == 1 action = args.first @the_action = action.to_sym render :action => 'actions' else path, action = args @the_action = action.to_sym render :template => "#{path}/actions" end end def the_action; @the_action end helper_method :the_action # # Url from String Path # def url_for_path path, options = {} unless options.delete :no_prefix url = ActionController::Base.relative_url_root + path else url = path end options = options.merge default_url_options url << "?#{options.to_query}" unless options.empty? url._url_format = options[:format] if options[:format] # for links with ajax support url end helper_method :url_for_path # # User Error # def catch_user_error begin yield rescue UserError => e flash[:error] = e.message do_not_persist_params do if request.xhr? or request.format == 'js' render :inline => "", :layout => 'application' else redirect_to default_path end end end end around_filter :catch_user_error class << self def prepare_model aclass, opt = {} id = opt.delete(:id) || :id variable = opt.delete(:variable) || aclass.model_name.underscore finder = opt.delete(:finder) || :find! method = "prepare_#{variable}" define_method method do model = aclass.send finder, params[id] instance_variable_set "@#{variable}", model end before_filter method, opt end end end