aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller/scaffolding.rb
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2005-06-12 05:33:23 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2005-06-12 05:33:23 +0000
commit3cb26e9cb3c1f3a069e7654988c650ca12322ede (patch)
tree1f60bc9bfb288f8fcb4c9576cdddf7b6708d2051 /actionpack/lib/action_controller/scaffolding.rb
parentdedb9c8483fc916bb5fd40d7e8a35af5f8e7a90b (diff)
downloadrails-3cb26e9cb3c1f3a069e7654988c650ca12322ede.tar.gz
rails-3cb26e9cb3c1f3a069e7654988c650ca12322ede.tar.bz2
rails-3cb26e9cb3c1f3a069e7654988c650ca12322ede.zip
r2495@sedna: jeremy | 2005-05-27 22:07:18 -0700
Branch to have scaffold use new render methods r2496@sedna: jeremy | 2005-05-28 10:50:51 -0700 axe unused process_request method r2497@sedna: jeremy | 2005-05-28 10:51:58 -0700 sanity assertions in process method check that @controller, @request, @response are set r2498@sedna: jeremy | 2005-05-28 10:53:42 -0700 clean up escaping. use instance_variable_get instead of instance_eval. put id in form action instead of hidden input (like the generated scaffolding) r2499@sedna: jeremy | 2005-05-28 10:54:46 -0700 clean up interpolation, remove tabs from stylesheet r2500@sedna: jeremy | 2005-05-28 10:56:40 -0700 modernize dynamic scaffolding. use params[:id] instead of @params[id]. use consolidated render method instead of render_action, render_file, etc. use builtin inflections rather than module methods. r2501@sedna: jeremy | 2005-05-28 11:00:26 -0700 modernize generated scaffolding. use new-style assertions; use params[:id] instead of @params[id]; use consolidated render method instead of render_* r2542@sedna: jeremy | 2005-06-12 02:24:06 -0700 use :id => model instead of :id => model.id. clean up the form helper method. use flash[:notice] instead of flash['notice']. r2543@sedna: jeremy | 2005-06-12 02:33:22 -0700 whitespace r2544@sedna: jeremy | 2005-06-12 02:56:57 -0700 update changelogs r2545@sedna: jeremy | 2005-06-12 03:26:23 -0700 test dynamic form help when @post is not a new record r2546@sedna: jeremy | 2005-06-12 03:44:14 -0700 touch up TestCase#process sanity assertions git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1404 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib/action_controller/scaffolding.rb')
-rw-r--r--actionpack/lib/action_controller/scaffolding.rb53
1 files changed, 29 insertions, 24 deletions
diff --git a/actionpack/lib/action_controller/scaffolding.rb b/actionpack/lib/action_controller/scaffolding.rb
index 4faa23cdf3..3435ce5108 100644
--- a/actionpack/lib/action_controller/scaffolding.rb
+++ b/actionpack/lib/action_controller/scaffolding.rb
@@ -27,12 +27,12 @@ module ActionController
# end
#
# def show
- # @entry = Entry.find(@params["id"])
+ # @entry = Entry.find(params[:id])
# render_scaffold
# end
#
# def destroy
- # Entry.find(@params["id"]).destroy
+ # Entry.find(params[:id]).destroy
# redirect_to :action => "list"
# end
#
@@ -42,9 +42,9 @@ module ActionController
# end
#
# def create
- # @entry = Entry.new(@params["entry"])
+ # @entry = Entry.new(params[:entry])
# if @entry.save
- # flash["notice"] = "Entry was successfully created"
+ # flash[:notice] = "Entry was successfully created"
# redirect_to :action => "list"
# else
# render_scaffold('new')
@@ -52,17 +52,17 @@ module ActionController
# end
#
# def edit
- # @entry = Entry.find(@params["id"])
+ # @entry = Entry.find(params[:id])
# render_scaffold
# end
#
# def update
- # @entry = Entry.find(@params["entry"]["id"])
- # @entry.attributes = @params["entry"]
+ # @entry = Entry.find(params[:id])
+ # @entry.attributes = params[:entry]
#
# if @entry.save
- # flash["notice"] = "Entry was successfully updated"
- # redirect_to :action => "show/" + @entry.id.to_s
+ # flash[:notice] = "Entry was successfully updated"
+ # redirect_to :action => "show", :id => @entry
# else
# render_scaffold('edit')
# end
@@ -84,9 +84,9 @@ module ActionController
def scaffold(model_id, options = {})
validate_options([ :class_name, :suffix ], options.keys)
- singular_name = model_id.id2name
- class_name = options[:class_name] || Inflector.camelize(singular_name)
- plural_name = Inflector.pluralize(singular_name)
+ singular_name = model_id.to_s
+ class_name = options[:class_name] || singular_name.camelize
+ plural_name = singular_name.pluralize
suffix = options[:suffix] ? "_#{singular_name}" : ""
unless options[:suffix]
@@ -104,12 +104,12 @@ module ActionController
end
def show#{suffix}
- @#{singular_name} = #{class_name}.find(@params["id"])
+ @#{singular_name} = #{class_name}.find(params[:id])
render#{suffix}_scaffold
end
def destroy#{suffix}
- #{class_name}.find(@params["id"]).destroy
+ #{class_name}.find(params[:id]).destroy
redirect_to :action => "list#{suffix}"
end
@@ -119,9 +119,9 @@ module ActionController
end
def create#{suffix}
- @#{singular_name} = #{class_name}.new(@params["#{singular_name}"])
+ @#{singular_name} = #{class_name}.new(params[:#{singular_name}])
if @#{singular_name}.save
- flash["notice"] = "#{class_name} was successfully created"
+ flash[:notice] = "#{class_name} was successfully created"
redirect_to :action => "list#{suffix}"
else
render#{suffix}_scaffold('new')
@@ -129,17 +129,17 @@ module ActionController
end
def edit#{suffix}
- @#{singular_name} = #{class_name}.find(@params["id"])
+ @#{singular_name} = #{class_name}.find(params[:id])
render#{suffix}_scaffold
end
def update#{suffix}
- @#{singular_name} = #{class_name}.find(@params["#{singular_name}"]["id"])
- @#{singular_name}.attributes = @params["#{singular_name}"]
+ @#{singular_name} = #{class_name}.find(params[:id])
+ @#{singular_name}.attributes = params[:#{singular_name}]
if @#{singular_name}.save
- flash["notice"] = "#{class_name} was successfully updated"
- redirect_to :action => "show#{suffix}", :id => @#{singular_name}.id.to_s
+ flash[:notice] = "#{class_name} was successfully updated"
+ redirect_to :action => "show#{suffix}", :id => @#{singular_name}
else
render#{suffix}_scaffold('edit')
end
@@ -148,7 +148,7 @@ module ActionController
private
def render#{suffix}_scaffold(action = caller_method_name(caller))
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}"
@@ -156,10 +156,15 @@ module ActionController
add_instance_variables_to_assigns
@content_for_layout = @template.render_file(scaffold_path(action.sub(/#{suffix}$/, "")), false)
- self.active_layout ? render_file(self.active_layout, "200 OK", true) : render_file(scaffold_path("layout"))
+
+ if active_layout?
+ render :file => active_layout, :use_full_path => true
+ else
+ render :file => scaffold_path("layout")
+ end
end
end
-
+
def scaffold_path(template_name)
File.dirname(__FILE__) + "/templates/scaffolds/" + template_name + ".rhtml"
end