Sha256: 11fcaf90f09df9511a269cf9e0f62e375f63ed74c61c9c7954c8057a4995be40

Contents?: true

Size: 1.92 KB

Versions: 96

Compression:

Stored size: 1.92 KB

Contents

class IshManager::TagsController < IshManager::ApplicationController

  before_action :set_lists

  def index
    @resource = City.find( params[:city_id] ) if params[:city_id]

    if @resource
      @tags = @resource.tags
    else
      @tags = Tag.unscoped.where( :parent_tag_id => nil ).order_by( :name => :asc )
    end

    authorize! :index, Tag.new

    @site = Site.find( params[:site_id] ) if params[:site_id] 
    @city = City.find( params[:city_id] ) if params[:city_id] 
  end
  
  def show
    @tag = Tag.unscoped.find params[:id]
    authorize! :show, @tag

    @galleries = @tag.galleries.unscoped.where( :is_trash => false ).page( params[:galleries_page] ).per( 10 )
    @videos = @tag.videos.unscoped.where( :is_trash => false ).page( params[:videos_page ]).per( 10 )
  end

  def new
    @tag = Tag.new
    authorize! :new, @tag
  end

  def create
    @tag = Tag.create params[:tag].permit!
    authorize! :create, @tag
    if @tag.save
      do_touch
      flash[:notice] = 'Success.'
      redirect_to tags_path
    else
      puts! @tag.errors, "error creating tag."
      flash[:alert] = "No luck. #{@tag.errors.messages}" 
      render :action => :new
    end
  end

  def edit
    @tag = Tag.unscoped.find params[:id]
    authorize! :edit, @tag
  end

  def update
    @tag = Tag.unscoped.find params[:id]
    authorize! :update, @tag

    if @tag.update_attributes params[:tag].permit!
      do_touch
      flash[:notice] = 'Success.'
      redirect_to tags_path
    else
      flash[:alert] = 'No luck.'
      render :action => :new
    end
  end

  def destroy
    @tag = Tag.unscoped.find params[:id]
    authorize! :destroy, @tag
    if @tag.destroy
      do_touch
      flash[:notice] = 'Success'
    else
      flash[:alert] = "Cannot destroy tag: #{@tag.errors.messages}"
    end
    redirect_to :action => 'index'
  end

  private

  def do_touch
    @tag.city.touch if @tag.city
    @tag.site.touch if @tag.site
  end

end


Version data entries

96 entries across 96 versions & 1 rubygems

Version Path
ish_manager-0.1.8.252 app/controllers/ish_manager/tags_controller.rb
ish_manager-0.1.8.251 app/controllers/ish_manager/tags_controller.rb
ish_manager-0.1.8.250 app/controllers/ish_manager/tags_controller.rb
ish_manager-0.1.8.249 app/controllers/ish_manager/tags_controller.rb
ish_manager-0.1.8.248 app/controllers/ish_manager/tags_controller.rb
ish_manager-0.1.8.247 app/controllers/ish_manager/tags_controller.rb
ish_manager-0.1.8.246 app/controllers/ish_manager/tags_controller.rb
ish_manager-0.1.8.245 app/controllers/ish_manager/tags_controller.rb
ish_manager-0.1.8.244 app/controllers/ish_manager/tags_controller.rb
ish_manager-0.1.8.243 app/controllers/ish_manager/tags_controller.rb
ish_manager-0.1.8.242 app/controllers/ish_manager/tags_controller.rb
ish_manager-0.1.8.241 app/controllers/ish_manager/tags_controller.rb
ish_manager-0.1.8.239 app/controllers/ish_manager/tags_controller.rb
ish_manager-0.1.8.238 app/controllers/ish_manager/tags_controller.rb
ish_manager-0.1.8.237 app/controllers/ish_manager/tags_controller.rb
ish_manager-0.1.8.236 app/controllers/ish_manager/tags_controller.rb
ish_manager-0.1.8.235 app/controllers/ish_manager/tags_controller.rb
ish_manager-0.1.8.234 app/controllers/ish_manager/tags_controller.rb
ish_manager-0.1.8.233 app/controllers/ish_manager/tags_controller.rb
ish_manager-0.1.8.232 app/controllers/ish_manager/tags_controller.rb