Class: IshManager::TagsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/ish_manager/tags_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#home

Instance Method Details

#createObject



27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/controllers/ish_manager/tags_controller.rb', line 27

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

#destroyObject



60
61
62
63
64
65
66
67
68
69
# File 'app/controllers/ish_manager/tags_controller.rb', line 60

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

#editObject



40
41
42
43
# File 'app/controllers/ish_manager/tags_controller.rb', line 40

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

#indexObject



6
7
8
9
10
11
12
# File 'app/controllers/ish_manager/tags_controller.rb', line 6

def index
  @tags = Tag.unscoped.where( :parent_tag_id => nil ).order_by( :name => :asc )
  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

#newObject



22
23
24
25
# File 'app/controllers/ish_manager/tags_controller.rb', line 22

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

#showObject



14
15
16
17
18
19
20
# File 'app/controllers/ish_manager/tags_controller.rb', line 14

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

#updateObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'app/controllers/ish_manager/tags_controller.rb', line 45

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

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