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