Sha256: 7c918d4f157e4019f1fa3240ba7ebc1b46856e92a84422050b5442d9bde568ef

Contents?: true

Size: 1.66 KB

Versions: 1

Compression:

Stored size: 1.66 KB

Contents

# 
# 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
      @the_action = action

      render :actions
      # @inline_js = js
      # render :template => 'layouts/application'
    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?
            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.name.underscore
      
      method = "prepare_#{variable}"
      define_method method do
        model = aclass.find!(params[id])
        instance_variable_set "@#{variable}", model
      end
      before_filter method, opt
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rails-ext-0.2.14 lib/rails_ext/action_controller_ext.rb