Skip to content

Commit

Permalink
Use render shortform
Browse files Browse the repository at this point in the history
  • Loading branch information
dhh committed Apr 8, 2014
1 parent cfcaaf3 commit acf3732
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions lib/generators/rails/templates/controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ def create
respond_to do |format|
if @<%= orm_instance.save %>
format.html { redirect_to @<%= singular_table_name %>, notice: <%= "'#{human_name} was successfully created.'" %> }
format.json { render action: 'show', status: :created, location: <%= "@#{singular_table_name}" %> }
format.json { render :show, status: :created, location: <%= "@#{singular_table_name}" %> }
else
format.html { render action: 'new' }
format.html { render :new }
format.json { render json: <%= "@#{orm_instance.errors}" %>, status: :unprocessable_entity }
end
end
Expand All @@ -48,9 +48,9 @@ def update
respond_to do |format|
if @<%= orm_instance.update("#{singular_table_name}_params") %>
format.html { redirect_to @<%= singular_table_name %>, notice: <%= "'#{human_name} was successfully updated.'" %> }
format.json { render action: 'show', status: :ok, location: <%= "@#{singular_table_name}" %> }
format.json { render :show, status: :ok, location: <%= "@#{singular_table_name}" %> }
else
format.html { render action: 'edit' }
format.html { render :edit }
format.json { render json: <%= "@#{orm_instance.errors}" %>, status: :unprocessable_entity }
end
end
Expand Down
8 changes: 4 additions & 4 deletions test/scaffold_controller_generator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ class ScaffoldControllerGeneratorTest < Rails::Generators::TestCase
assert_match /@post = Post\.new\(post_params\)/, m
assert_match /@post\.save/, m
assert_match /format\.html \{ redirect_to @post, notice: 'Post was successfully created\.' \}/, m
assert_match /format\.json \{ render action: 'show', status: :created, location: @post \}/, m
assert_match /format\.html \{ render action: 'new' \}/, m
assert_match /format\.json \{ render :show, status: :created, location: @post \}/, m
assert_match /format\.html \{ render :new \}/, m
assert_match /format\.json \{ render json: @post\.errors, status: :unprocessable_entity \}/, m
end

assert_instance_method :update, content do |m|
assert_match /format\.html \{ redirect_to @post, notice: 'Post was successfully updated\.' \}/, m
assert_match /format\.json \{ render action: 'show', status: :ok, location: @post \}/, m
assert_match /format\.html \{ render action: 'edit' \}/, m
assert_match /format\.json \{ render :show, status: :ok, location: @post \}/, m
assert_match /format\.html \{ render :edit \}/, m
assert_match /format\.json \{ render json: @post.errors, status: :unprocessable_entity \}/, m
end

Expand Down

0 comments on commit acf3732

Please sign in to comment.