Merge pull request #3197 from ktkaushik/my-modifications

optimizied code for destroy action under tag_followings_controller.rb [ci skip]
This commit is contained in:
Sean Tilley 2012-04-28 21:27:47 -07:00
commit cf129b52ab

View file

@ -25,7 +25,6 @@ class TagFollowingsController < ApplicationController
flash[:error] = I18n.t('tag_followings.create.failure', :name => name_normalized)
end
end
redirect_to :back
end
@ -33,25 +32,23 @@ class TagFollowingsController < ApplicationController
# DELETE /tag_followings/1.xml
def destroy
@tag = ActsAsTaggableOn::Tag.find_by_name(params[:name])
@tag_following = current_user.tag_followings.where(:tag_id => @tag.id).first
if @tag_following && @tag_following.destroy
@tag_unfollowed = true
tag_following = current_user.tag_followings.find_by_tag_id( @tag.id )
if tag_following && tag_following.destroy
tag_unfollowed = true
else
@tag_unfollowed = false
tag_unfollowed = false
end
if params[:remote]
respond_to do |format|
format.js { render 'tags/update' }
format.any {}
end
else
if @tag_unfollowed
format.any {
if tag_unfollowed
flash[:notice] = I18n.t('tag_followings.destroy.success', :name => params[:name])
else
flash[:error] = I18n.t('tag_followings.destroy.failure', :name => params[:name])
end
redirect_to tag_path(:name => params[:name])
}
end
end