Skip to content

Commit

Permalink
Merge pull request igrigorik#195 from igrigorik/adding_redirect_in_re…
Browse files Browse the repository at this point in the history
…scue

Removed empty rescue blocks in controllers
  • Loading branch information
zoso10 committed Feb 2, 2017
2 parents 3da713f + b0c98e2 commit 7555ab9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 32 deletions.
10 changes: 3 additions & 7 deletions app/controllers/challenges_controller.rb
Expand Up @@ -14,13 +14,9 @@ def new
end

def destroy
begin
@challenge = Challenge.find(params['id'])
@challenge.destroy if @challenge.owner?(current_user)
rescue Exception => e
ensure
redirect_to root_path
end
@challenge = Challenge.find(params['id'])
@challenge.destroy if @challenge.owner?(current_user)
redirect_to root_path
end

def create
Expand Down
40 changes: 15 additions & 25 deletions app/controllers/entry_controller.rb
@@ -1,16 +1,14 @@
class EntryController < ApplicationController

before_filter :login, :only => [:comment]
before_filter :load_entry, :only => [:comment]
before_filter :load_entry, :only => [:comment, :destroy]

def comment
if @challenge.participator?(current_user) && params[:comment] && params[:comment][:text].size > 0
if @challenge.participator?(current_user) && @entry && params.fetch(:comment, {})[:text].present?
@entry.comments.push Comment.new(:comment => params[:comment][:text], :nickname => current_user.nickname)
@challenge.save
end
rescue

ensure
redirect_to challenge_path(params[:challenge])
end

Expand Down Expand Up @@ -44,33 +42,25 @@ def create
end

def destroy
challenge = Challenge.find(params[:challenge])
entry = challenge.entries.find(params[:entry])

if challenge.owner?(current_user) || entry.owner?(current_user)
entry.destroy
challenge.save

flash[:notice] = "Deleted entry"
if @entry && (@challenge.owner?(current_user) || @entry.owner?(current_user))
@entry.destroy
@challenge.save
end

redirect_to challenge_path(params[:challenge])
rescue
redirect_to root_path
end

private

def load_entry
@challenge = Challenge.find(params[:challenge])
@entry = @challenge.entries.find(params[:entry])

rescue
respond_to do |format|
format.json {
render :json => {'status' => 'failed'}, :status => 400
}
format.html { redirect_to root_path }
end
def load_entry
@challenge = Challenge.find(params[:challenge])
@entry = @challenge.entries.find(params[:entry])
rescue
respond_to do |format|
format.json {
render :json => {'status' => 'failed'}, :status => 400
}
format.html { redirect_to root_path }
end
end
end

0 comments on commit 7555ab9

Please sign in to comment.