forked from rails/rails
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated scaffold_controller generator to use respond_to and
respond_with (ht: radar)
- Loading branch information
Showing
2 changed files
with
13 additions
and
38 deletions.
There are no files selected for viewing
49 changes: 13 additions & 36 deletions
49
railties/lib/rails/generators/rails/scaffold_controller/templates/controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,49 @@ | ||
<% module_namespacing do -%> | ||
class <%= controller_class_name %>Controller < ApplicationController | ||
respond_to :html, :xml | ||
|
||
def index | ||
@<%= plural_table_name %> = <%= orm_class.all(class_name) %> | ||
|
||
respond_to do |format| | ||
format.html # index.html.erb | ||
format.xml { render :xml => @<%= plural_table_name %> } | ||
end | ||
respond_with(@<%= plural_table_name %>) | ||
end | ||
def show | ||
@<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %> | ||
|
||
respond_to do |format| | ||
format.html # show.html.erb | ||
format.xml { render :xml => @<%= singular_table_name %> } | ||
end | ||
respond_with(@<%= singular_table_name %>) | ||
end | ||
|
||
def new | ||
@<%= singular_table_name %> = <%= orm_class.build(class_name) %> | ||
|
||
respond_to do |format| | ||
format.html # new.html.erb | ||
format.xml { render :xml => @<%= singular_table_name %> } | ||
end | ||
respond_with(@<%= singular_table_name %>) | ||
end | ||
def edit | ||
@<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %> | ||
respond_with(@<%= singular_table_name %>) | ||
end | ||
|
||
def create | ||
@<%= singular_table_name %> = <%= orm_class.build(class_name, "params[:#{singular_table_name}]") %> | ||
|
||
respond_to do |format| | ||
if @<%= orm_instance.save %> | ||
format.html { redirect_to(@<%= singular_table_name %>, :notice => '<%= human_name %> was successfully created.') } | ||
format.xml { render :xml => @<%= singular_table_name %>, :status => :created, :location => @<%= singular_table_name %> } | ||
else | ||
format.html { render :action => "new" } | ||
format.xml { render :xml => @<%= orm_instance.errors %>, :status => :unprocessable_entity } | ||
end | ||
if @<%= orm_instance.save %> | ||
flash[:notice] = "<%= human_name %> successfully created." | ||
end | ||
respond_with(@<%= singular_table_name %>) | ||
end | ||
def update | ||
@<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %> | ||
respond_to do |format| | ||
if @<%= orm_instance.update_attributes("params[:#{singular_table_name}]") %> | ||
format.html { redirect_to(@<%= singular_table_name %>, :notice => '<%= human_name %> was successfully updated.') } | ||
format.xml { head :ok } | ||
else | ||
format.html { render :action => "edit" } | ||
format.xml { render :xml => @<%= orm_instance.errors %>, :status => :unprocessable_entity } | ||
end | ||
if @<%= orm_instance.update_attributes("params[:#{singular_table_name}]") %> | ||
flash[:notice] = "<%= human_name %> successfully created." | ||
end | ||
respond_with(@<%= singular_table_name %>) | ||
end | ||
|
||
def destroy | ||
@<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %> | ||
@<%= orm_instance.destroy %> | ||
respond_to do |format| | ||
format.html { redirect_to(<%= index_helper %>_url) } | ||
format.xml { head :ok } | ||
end | ||
respond_with(@<%= singular_table_name %>) | ||
end | ||
end | ||
<% end -%> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters