Skip to content

Commit

Permalink
Use respond_with for EventsController#create. [#64]
Browse files Browse the repository at this point in the history
  • Loading branch information
marnen committed Dec 29, 2011
1 parent c21d6eb commit 246fca5
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 71 deletions.
4 changes: 2 additions & 2 deletions app/controllers/calendars_controller.rb
Expand Up @@ -17,7 +17,7 @@ def new

def create
@calendar = Calendar.new params[:calendar]
if @calendar.save!
if @calendar.save
make_admin_permission_for @calendar
redirect_to '/admin', notice: _('Your calendar was successfully created.')
else
Expand All @@ -32,7 +32,7 @@ def edit
end

def update
if @calendar.update_attributes! params[:calendar]
if @calendar.update_attributes params[:calendar]
redirect_to '/admin', notice: _('Your calendar was successfully saved.')
else
flash[:error] = _('Couldn\'t save your calendar!')
Expand Down
16 changes: 13 additions & 3 deletions app/controllers/events_controller.rb
Expand Up @@ -29,8 +29,18 @@ def new
@event = Event.new
end

def create
@event = Event.new params[:event]
if @event.save
redirect_to({action: :index}, notice: _("Your event has been saved."))
else
flash[:error] = _("We couldn't process that request. Please try again.")
respond_with @event
end
end

make_resourceful do
actions :create, :edit, :update, :show
actions :edit, :update, :show

response_for :edit do
if !current_object.allow?(:edit)
Expand All @@ -42,12 +52,12 @@ def new
end
end

response_for :update, :create do
response_for :update do
flash[:notice] = _("Your event has been saved.")
redirect_to :action => :index
end

response_for :update_fails, :create_fails do
response_for :update_fails do
flash[:error] = _("We couldn't process that request. Please try again.")
render :new
end
Expand Down

0 comments on commit 246fca5

Please sign in to comment.