0
class_name = options[:class_name] || singular_name.camelize
0
plural_name = singular_name.pluralize
0
will_paginate_index = options[:will_paginate] || false
0
- url_string = "#{singular_name}_url(@#{singular_name})"
0
- list_url_string = "#{plural_name}_url"
0
- finder_base = class_name
0
+ resource_url = "#{singular_name}_url(@#{singular_name})"
0
+ collection_url = "#{plural_name}_url"
0
+ resource_url = options[:path_prefix] + resource_url unless options[:path_prefix].nil?
0
+ collection_url = options[:path_prefix] + collection_url unless options[:path_prefix].nil?
0
class_inheritable_accessor :resource_this_finder_options
0
self.resource_this_finder_options = options[:finder_options] || {}
0
unless options[:nested].nil?
0
- nested = options[:nested].to_s.singularize
0
- nested_class = nested.camelize
0
- url_string = "#{nested}_#{singular_name}_url(" + [nested, singular_name].map { |route| "@#{route}"}.join(', ') + ')'
0
- list_url_string = "#{nested}_#{plural_name}_url(@#{nested})"
0
- finder_base = "@#{nested}.#{plural_name}"
0
+ nested = options[:nested].to_s.singularize
0
+ nested_class = nested.camelize
0
+ nested_resource_url = "#{nested}_#{singular_name}_url(" + [nested, singular_name].map { |route| "@#{route}"}.join(', ') + ')'
0
+ nested_collection_url = "#{nested}_#{plural_name}_url(@#{nested})"
0
+ nested_resource_url = options[:path_prefix] + nested_resource_url unless options[:path_prefix].nil?
0
+ nested_collection_url = options[:path_prefix] + nested_collection_url unless options[:path_prefix].nil?
0
module_eval <<-"end_eval", __FILE__, __LINE__
0
before_filter :load_#{nested}
0
- url_string = options[:path_prefix] + url_string unless options[:path_prefix].nil?
0
- list_url_string = options[:path_prefix] + list_url_string unless options[:path_prefix].nil?
0
#standard before_filters
0
module_eval <<-"end_eval", __FILE__, __LINE__
0
before_filter :load_#{singular_name}, :only => [ :show, :edit, :update, :destroy ]
0
before_filter :create_#{singular_name}, :only => [ :create ]
0
before_filter :update_#{singular_name}, :only => [ :update ]
0
before_filter :destroy_#{singular_name}, :only => [ :destroy ]
0
+ resource_this_finder_options.class == Proc ? resource_this_finder_options.call : {}
0
-
unless options[:nested].nil?
0
+
if options[:nested].nil?
0
module_eval <<-"end_eval", __FILE__, __LINE__
0
+ #{class_name}.find(:all, finder_options)
0
+ module_eval <<-"end_eval", __FILE__, __LINE__
0
- @#{nested} = #{nested_class}.find(params[:#{nested}_id])
0
+ @#{nested} = #{nested_class}.find(params[:#{nested}_id])
rescue nil0
+ @#{nested}.nil? ? #{class_name} : @#{nested}.#{plural_name}
0
+ @#{nested}.nil? ? #{class_name}.find(:all, finder_options) : @#{nested}.#{plural_name}.find(:all, finder_options)
0
+ @#{nested}.nil? ? #{collection_url} : #{nested_collection_url}
0
+ @#{nested}.nil? ? #{resource_url} : #{nested_resource_url}
0
module_eval <<-"end_eval", __FILE__, __LINE__
0
def load_#{singular_name}
0
- @#{singular_name} =
#{finder_base}.find(params[:id])
0
+ @#{singular_name} =
finder_base.find(params[:id])
0
def new_#{singular_name}
0
- @#{singular_name} =
#{finder_base}.new
0
+ @#{singular_name} =
finder_base.new
0
def create_#{singular_name}
0
- @#{singular_name} =
#{finder_base}.new(params[:#{singular_name}])
0
+ @#{singular_name} =
finder_base.new(params[:#{singular_name}])
0
@created = @#{singular_name}.save
0
- #TODO: add sorting customizable by subclassed controllers
0
module_eval <<-"end_eval", __FILE__, __LINE__
0
def load_#{plural_name}
0
- finder_options = resource_this_finder_options.class == Proc ? resource_this_finder_options.call : resource_this_finder_options
0
- @#{plural_name} = #{finder_base}.paginate(finder_options.merge(:page => params[:page]))
0
+ @#{plural_name} = finder_base.paginate(finder_options.merge(:page => params[:page]))
0
module_eval <<-"end_eval", __FILE__, __LINE__
0
def load_#{plural_name}
0
- finder_options = resource_this_finder_options.class == Proc ? resource_this_finder_options.call : resource_this_finder_options
0
- @#{plural_name} = #{finder_base}.find(:all, finder_options)
0
+ @#{plural_name} = collection
0
flash[:notice] = '#{class_name} was successfully created.'
0
- format.html { redirect_to #{url_string} }
0
- format.xml { render :xml => @#{singular_name}, :status => :created, :location => #{url_string} }
0
+ format.html { redirect_to(resource_url) }
0
+ format.xml { render :xml => @#{singular_name}, :status => :created, :location => resource_url }
0
format.html { render :action => :edit }
0
flash[:notice] = '#{class_name} was successfully updated.'
0
- format.html { redirect_to
#{url_string} }
0
+ format.html { redirect_to
(resource_url) }
0
format.xml { head :ok }
0
- format.html { redirect_to
#{list_url_string} }
0
+ format.html { redirect_to
(collection_url) }
0
format.xml { head :ok }
Comments
No one has commented yet.