journalduhacker/app/controllers/filters_controller.rb

34 lines
830 B
Ruby

class FiltersController < ApplicationController
before_filter :authenticate_user
def index
@cur_url = "/filters"
@title = I18n.t 'controllers.filters_controller.filterstitle'
@tags = Tag.active.all_with_story_counts_for(@user)
if @user
@filtered_tags = @user.tag_filter_tags.to_a
else
@filtered_tags = tags_filtered_by_cookie.to_a
end
end
def update
tags_param = params[:tags]
new_tags = tags_param.blank? ? [] :
Tag.active.where(:tag => tags_param).to_a
new_tags.keep_if {|t| t.valid_for? @user }
if @user
@user.tag_filter_tags = new_tags
else
cookies.permanent[TAG_FILTER_COOKIE] = new_tags.map(&:tag).join(",")
end
flash[:success] = I18n.t 'controllers.filters_controller.flashfilterupdate'
redirect_to filters_path
end
end