diff options
Diffstat (limited to 'actionpack/lib/action_controller')
7 files changed, 61 insertions, 51 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 diff --git a/actionpack/lib/action_controller/templates/scaffolds/edit.rhtml b/actionpack/lib/action_controller/templates/scaffolds/edit.rhtml index 31e15f7501..63dff602a1 100644 --- a/actionpack/lib/action_controller/templates/scaffolds/edit.rhtml +++ b/actionpack/lib/action_controller/templates/scaffolds/edit.rhtml @@ -1,7 +1,7 @@ <h1>Editing <%= @scaffold_singular_name %></h1> <%= error_messages_for(@scaffold_singular_name) %> -<%= form(@scaffold_singular_name, :action => "update" + @scaffold_suffix) %> +<%= form(@scaffold_singular_name, :action => "update#{@scaffold_suffix}") %> -<%= link_to "Show", :action => "show#{@scaffold_suffix}", :id => instance_variable_get("@#{@scaffold_singular_name}").id %> | +<%= link_to "Show", :action => "show#{@scaffold_suffix}", :id => instance_variable_get("@#{@scaffold_singular_name}") %> | <%= link_to "Back", :action => "list#{@scaffold_suffix}" %> diff --git a/actionpack/lib/action_controller/templates/scaffolds/layout.rhtml b/actionpack/lib/action_controller/templates/scaffolds/layout.rhtml index 300aa1d77a..80996985d2 100644 --- a/actionpack/lib/action_controller/templates/scaffolds/layout.rhtml +++ b/actionpack/lib/action_controller/templates/scaffolds/layout.rhtml @@ -28,40 +28,40 @@ #ErrorExplanation { width: 400px; - border: 2px solid 'red'; - padding: 7px; - padding-bottom: 12px; - margin-bottom: 20px; - background-color: #f0f0f0; + border: 2px solid 'red'; + padding: 7px; + padding-bottom: 12px; + margin-bottom: 20px; + background-color: #f0f0f0; } #ErrorExplanation h2 { - text-align: left; - font-weight: bold; - padding: 5px 5px 5px 15px; - font-size: 12px; - margin: -7px; - background-color: #c00; - color: #fff; + text-align: left; + font-weight: bold; + padding: 5px 5px 5px 15px; + font-size: 12px; + margin: -7px; + background-color: #c00; + color: #fff; } #ErrorExplanation p { - color: #333; - margin-bottom: 0; - padding: 5px; + color: #333; + margin-bottom: 0; + padding: 5px; } #ErrorExplanation ul li { - font-size: 12px; - list-style: square; + font-size: 12px; + list-style: square; } </style> </head> <body> -<p style="color: green"><%= flash['notice'] %></p> +<p style="color: green"><%= flash[:notice] %></p> <%= @content_for_layout %> </body> -</html>
\ No newline at end of file +</html> diff --git a/actionpack/lib/action_controller/templates/scaffolds/list.rhtml b/actionpack/lib/action_controller/templates/scaffolds/list.rhtml index 233e9da87d..d1196a1599 100644 --- a/actionpack/lib/action_controller/templates/scaffolds/list.rhtml +++ b/actionpack/lib/action_controller/templates/scaffolds/list.rhtml @@ -12,9 +12,9 @@ <% for column in @scaffold_class.content_columns %> <td><%= entry.send(column.name) %></td> <% end %> - <td><%= link_to "Show", :action => "show#{@scaffold_suffix}", :id => entry.id %></td> - <td><%= link_to "Edit", :action => "edit#{@scaffold_suffix}", :id => entry.id %></td> - <td><%= link_to "Destroy", :action => "destroy#{@scaffold_suffix}", :id => entry.id, :confirm => "Are you sure?" %></td> + <td><%= link_to "Show", :action => "show#{@scaffold_suffix}", :id => entry %></td> + <td><%= link_to "Edit", :action => "edit#{@scaffold_suffix}", :id => entry %></td> + <td><%= link_to "Destroy", :action => "destroy#{@scaffold_suffix}", :id => entry, :confirm => "Are you sure?" %></td> </tr> <% end %> </table> diff --git a/actionpack/lib/action_controller/templates/scaffolds/new.rhtml b/actionpack/lib/action_controller/templates/scaffolds/new.rhtml index 74db8468bd..66f6626f4e 100644 --- a/actionpack/lib/action_controller/templates/scaffolds/new.rhtml +++ b/actionpack/lib/action_controller/templates/scaffolds/new.rhtml @@ -1,6 +1,6 @@ <h1>New <%= @scaffold_singular_name %></h1> <%= error_messages_for(@scaffold_singular_name) %> -<%= form(@scaffold_singular_name, :action => "create" + @scaffold_suffix) %> +<%= form(@scaffold_singular_name, :action => "create#{@scaffold_suffix}") %> -<%= link_to "Back", :action => "list#{@scaffold_suffix}" %>
\ No newline at end of file +<%= link_to "Back", :action => "list#{@scaffold_suffix}" %> diff --git a/actionpack/lib/action_controller/templates/scaffolds/show.rhtml b/actionpack/lib/action_controller/templates/scaffolds/show.rhtml index 10c46342fd..46cdfdb493 100644 --- a/actionpack/lib/action_controller/templates/scaffolds/show.rhtml +++ b/actionpack/lib/action_controller/templates/scaffolds/show.rhtml @@ -5,5 +5,5 @@ </p> <% end %> -<%= link_to "Edit", :action => "edit#{@scaffold_suffix}", :id => instance_variable_get("@#{@scaffold_singular_name}").id %> | +<%= link_to "Edit", :action => "edit#{@scaffold_suffix}", :id => instance_variable_get("@#{@scaffold_singular_name}") %> | <%= link_to "Back", :action => "list#{@scaffold_suffix}" %> diff --git a/actionpack/lib/action_controller/test_process.rb b/actionpack/lib/action_controller/test_process.rb index 25ad540468..20022aab91 100644 --- a/actionpack/lib/action_controller/test_process.rb +++ b/actionpack/lib/action_controller/test_process.rb @@ -247,6 +247,11 @@ module Test private # execute the request and set/volley the response def process(action, parameters = nil, session = nil, flash = nil) + # Sanity check for required instance variables so we can give an understandable error message. + %w(controller request response).each do |iv_name| + assert_not_nil instance_variable_get("@#{iv_name}"), "@#{iv_name} is nil: make sure you set it in your test's setup method." + end + @html_document = nil @request.env['REQUEST_METHOD'] ||= "GET" @request.action = action.to_s |