Class: IshLibManager::FeaturesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/ish_lib_manager/features_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#set_lists

Instance Method Details

#createObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/controllers/ish_lib_manager/features_controller.rb', line 14

def create
  authorize! :create, ManagerFeature.new

  @feature = Feature.new params[:feature].permit( :name, :subhead, :image_path, :link_path, :partial_name, :photo, :weight,
                                                  :report, :report_id, :gallery, :gallery_id, :video, :video_id
                                                )
  if params[:city_id]
    @city = City.find params[:city_id]
    @city.features << @feature
    redirect_path = manager_cities_path
  end
  if params[:site_id]
    @site = Site.find params[:site_id]
    @site.features << @feature
    redirect_path = manager_sites_path
  end
  if params[:tag_id]
    @tag = Tag.find params[:tag_id]
    @tag.features << @feature
    redirect_path = manager_tags_path
  end

  if (@city && @city.save) || (@site && @site.save) || (@tag && @tag.save)
    flash[:notice] = 'Success.'
    redirect_to redirect_path
  else
    flash[:error] = 'No Luck. ' + ( @city || @site || @tag ).errors.inspect
    render :action => :new
  end
end

#destroyObject



108
109
110
111
112
113
114
115
116
117
118
119
# File 'app/controllers/ish_lib_manager/features_controller.rb', line 108

def destroy
  if params[:tag_id]
    @resource = Tag.find params[:tag_id]
  end
  @feature = @resource.features.find params[:id]
  if @feature.destroy
    flash[:notice] = :'Success.' 
  else
    flash[:error] = :'No luck.'
  end
  redirect_to request.referrer
end

#editObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'app/controllers/ish_lib_manager/features_controller.rb', line 45

def edit
  authorize! :edit, ManagerCity.new
  
  if params[:city_id]
    @city = City.find params[:city_id]
    @feature = @city.features.find params[:id]
  end

  if params[:site_id]
    @site = Site.find params[:site_id]
    @feature = @site.features.find params[:id]
  end

  if params[:tag_id]
    @tag = Tag.find params[:tag_id]
    @feature = @tag.features.find params[:id]
  end
 
  if params[:venue_id]
    @venue = Tag.find params[:venue_id]
    @feature = @venue.features.find params[:id]
  end

end

#indexObject



101
102
103
104
105
106
# File 'app/controllers/ish_lib_manager/features_controller.rb', line 101

def index
  if params[:tag_id]
    @resource = Tag.find params[:tag_id]
  end
  
end

#newObject



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

def new
  authorize! :new, ManagerFeature.new
  @city = City.find params[:city_id] unless params[:city_id].blank?
  @site = Site.find params[:site_id] unless params[:site_id].blank?
  @tag = Tag.find params[:tag_id] unless params[:tag_id].blank?
  @feature = Feature.new
end

#updateObject



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'app/controllers/ish_lib_manager/features_controller.rb', line 70

def update
  unless params[:city_id].blank?
    @city = City.find params[:city_id] 
    authorize! :update, ManagerCity.new
    @feature = @city.features.find params[:id]
    redirect_path = manager_city_path( @city )
  end
  unless params[:site_id].blank?
    @site = Site.find params[:site_id] 
    authorize! :update, ManagerSite.new
    @feature = @site.features.find params[:id]
    redirect_path = manager_site_path( @site )
  end
  unless params[:tag_id].blank?
    @tag = Tag.find params[:tag_id]
    authorize! :update, ManagerTag.new
    @feature = @tag.features.find params[:id]
    redirect_path = manager_tag_path( @tag )
  end
  
  if @feature.update_attributes params[:feature].permit( :name, :subhead, :image_path, :link_path, :partial_name, :weight,
                                                         :photo_id, :photo, :report_id, :gallery_id, :video_id )
    flash[:notice] = 'Success'
    redirect_to redirect_path
  else
    flash[:error] = 'No Luck. ' + @feature.errors.inspect
    puts! @feature.errors, 'Errors updating feature'
    render :action => :edit_feature
  end    
end