Skip to content

Commit

Permalink
Updated scaffold_controller generator to use respond_to and
Browse files Browse the repository at this point in the history
respond_with (ht: radar)
  • Loading branch information
Breccan committed Mar 22, 2011
1 parent 4af072e commit f7e31e1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 38 deletions.
@@ -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 -%>
Expand Up @@ -35,13 +35,11 @@ def test_controller_skeleton_is_created
assert_instance_method :create, content do |m|
assert_match /@user = User\.new\(params\[:user\]\)/, m
assert_match /@user\.save/, m
assert_match /@user\.errors/, m
end

assert_instance_method :update, content do |m|
assert_match /@user = User\.find\(params\[:id\]\)/, m
assert_match /@user\.update_attributes\(params\[:user\]\)/, m
assert_match /@user\.errors/, m
end

assert_instance_method :destroy, content do |m|
Expand Down

0 comments on commit f7e31e1

Please sign in to comment.