Don't use deprecated render API. Cosmetics.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4973 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
7cbb4ac44f
commit
96c45a8118
|
@ -27,22 +27,22 @@ module ActionController
|
|||
# @entries = Entry.find(:all)
|
||||
# render_scaffold "list"
|
||||
# end
|
||||
#
|
||||
#
|
||||
# def show
|
||||
# @entry = Entry.find(params[:id])
|
||||
# render_scaffold
|
||||
# end
|
||||
#
|
||||
#
|
||||
# def destroy
|
||||
# Entry.find(params[:id]).destroy
|
||||
# redirect_to :action => "list"
|
||||
# end
|
||||
#
|
||||
#
|
||||
# def new
|
||||
# @entry = Entry.new
|
||||
# render_scaffold
|
||||
# end
|
||||
#
|
||||
#
|
||||
# def create
|
||||
# @entry = Entry.new(params[:entry])
|
||||
# if @entry.save
|
||||
|
@ -52,16 +52,16 @@ module ActionController
|
|||
# render_scaffold('new')
|
||||
# end
|
||||
# end
|
||||
#
|
||||
#
|
||||
# def edit
|
||||
# @entry = Entry.find(params[:id])
|
||||
# render_scaffold
|
||||
# end
|
||||
#
|
||||
#
|
||||
# def update
|
||||
# @entry = Entry.find(params[:id])
|
||||
# @entry.attributes = params[:entry]
|
||||
#
|
||||
#
|
||||
# if @entry.save
|
||||
# flash[:notice] = "Entry was successfully updated"
|
||||
# redirect_to :action => "show", :id => @entry
|
||||
|
@ -71,17 +71,17 @@ module ActionController
|
|||
# end
|
||||
# end
|
||||
#
|
||||
# The <tt>render_scaffold</tt> method will first check to see if you've made your own template (like "weblog/show.rhtml" for
|
||||
# the show action) and if not, then render the generic template for that action. This gives you the possibility of using the
|
||||
# scaffold while you're building your specific application. Start out with a totally generic setup, then replace one template
|
||||
# The <tt>render_scaffold</tt> method will first check to see if you've made your own template (like "weblog/show.rhtml" for
|
||||
# the show action) and if not, then render the generic template for that action. This gives you the possibility of using the
|
||||
# scaffold while you're building your specific application. Start out with a totally generic setup, then replace one template
|
||||
# and one action at a time while relying on the rest of the scaffolded templates and actions.
|
||||
module ClassMethods
|
||||
# Adds a swath of generic CRUD actions to the controller. The +model_id+ is automatically converted into a class name unless
|
||||
# one is specifically provide through <tt>options[:class_name]</tt>. So <tt>scaffold :post</tt> would use Post as the class
|
||||
# and @post/@posts for the instance variables.
|
||||
#
|
||||
#
|
||||
# It's possible to use more than one scaffold in a single controller by specifying <tt>options[:suffix] = true</tt>. This will
|
||||
# make <tt>scaffold :post, :suffix => true</tt> use method names like list_post, show_post, and create_post
|
||||
# make <tt>scaffold :post, :suffix => true</tt> use method names like list_post, show_post, and create_post
|
||||
# instead of just list, show, and post. If suffix is used, then no index method is added.
|
||||
def scaffold(model_id, options = {})
|
||||
options.assert_valid_keys(:class_name, :suffix)
|
||||
|
@ -98,13 +98,13 @@ module ActionController
|
|||
end
|
||||
end_eval
|
||||
end
|
||||
|
||||
|
||||
module_eval <<-"end_eval", __FILE__, __LINE__
|
||||
|
||||
|
||||
verify :method => :post, :only => [ :destroy#{suffix}, :create#{suffix}, :update#{suffix} ],
|
||||
:redirect_to => { :action => :list#{suffix} }
|
||||
|
||||
|
||||
|
||||
|
||||
def list#{suffix}
|
||||
@#{singular_name}_pages, @#{plural_name} = paginate :#{plural_name}, :per_page => 10
|
||||
render#{suffix}_scaffold "list#{suffix}"
|
||||
|
@ -114,17 +114,17 @@ module ActionController
|
|||
@#{singular_name} = #{class_name}.find(params[:id])
|
||||
render#{suffix}_scaffold
|
||||
end
|
||||
|
||||
|
||||
def destroy#{suffix}
|
||||
#{class_name}.find(params[:id]).destroy
|
||||
redirect_to :action => "list#{suffix}"
|
||||
end
|
||||
|
||||
|
||||
def new#{suffix}
|
||||
@#{singular_name} = #{class_name}.new
|
||||
render#{suffix}_scaffold
|
||||
end
|
||||
|
||||
|
||||
def create#{suffix}
|
||||
@#{singular_name} = #{class_name}.new(params[:#{singular_name}])
|
||||
if @#{singular_name}.save
|
||||
|
@ -134,12 +134,12 @@ module ActionController
|
|||
render#{suffix}_scaffold('new')
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def edit#{suffix}
|
||||
@#{singular_name} = #{class_name}.find(params[:id])
|
||||
render#{suffix}_scaffold
|
||||
end
|
||||
|
||||
|
||||
def update#{suffix}
|
||||
@#{singular_name} = #{class_name}.find(params[:id])
|
||||
@#{singular_name}.attributes = params[:#{singular_name}]
|
||||
|
@ -151,14 +151,14 @@ module ActionController
|
|||
render#{suffix}_scaffold('edit')
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
def render#{suffix}_scaffold(action=nil)
|
||||
action ||= caller_method_name(caller)
|
||||
# logger.info ("testing template:" + "\#{self.class.controller_path}/\#{action}") if logger
|
||||
|
||||
|
||||
if template_exists?("\#{self.class.controller_path}/\#{action}")
|
||||
render_action(action)
|
||||
render :action => action
|
||||
else
|
||||
@scaffold_class = #{class_name}
|
||||
@scaffold_singular_name, @scaffold_plural_name = "#{singular_name}", "#{plural_name}"
|
||||
|
@ -168,9 +168,9 @@ module ActionController
|
|||
@template.instance_variable_set("@content_for_layout", @template.render_file(scaffold_path(action.sub(/#{suffix}$/, "")), false))
|
||||
|
||||
if !active_layout.nil?
|
||||
render_file(active_layout, nil, true)
|
||||
render :file => active_layout, :use_full_path => true
|
||||
else
|
||||
render_file(scaffold_path("layout"))
|
||||
render :file => scaffold_path('layout')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -178,12 +178,12 @@ module ActionController
|
|||
def scaffold_path(template_name)
|
||||
File.dirname(__FILE__) + "/templates/scaffolds/" + template_name + ".rhtml"
|
||||
end
|
||||
|
||||
|
||||
def caller_method_name(caller)
|
||||
caller.first.scan(/`(.*)'/).first.first # ' ruby-mode
|
||||
end
|
||||
end_eval
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,23 +5,21 @@ class Address
|
|||
def Address.count(conditions = nil, join = nil)
|
||||
nil
|
||||
end
|
||||
|
||||
|
||||
def Address.find_all(arg1, arg2, arg3, arg4)
|
||||
[]
|
||||
end
|
||||
|
||||
|
||||
def self.find(*args)
|
||||
[]
|
||||
end
|
||||
end
|
||||
|
||||
class AddressesTestController < ActionController::Base
|
||||
|
||||
scaffold :address
|
||||
|
||||
def self.controller_name; "addresses"; end
|
||||
def self.controller_path; "addresses"; end
|
||||
|
||||
end
|
||||
|
||||
AddressesTestController.template_root = File.dirname(__FILE__) + "/../fixtures/"
|
||||
|
@ -44,6 +42,4 @@ class AddressesTest < Test::Unit::TestCase
|
|||
get :list
|
||||
assert_equal "We only need to get this far!", @response.body.chomp
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue