Class: IshManager::FeaturesController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

#home

Instance Method Details

#createObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'app/controllers/ish_manager/features_controller.rb', line 21

def create
  @feature = Feature.new params[:feature].permit!

  if params[:city_id]
    @city = City.find params[:city_id]
    authorize! :create_feature, @city
    @city.features << @feature
    @city.touch
    redirect_path = cities_path
  end
  if params[:site_id]
    @site = Site.find params[:site_id]
    authorize! :create_feature, @site
    @site.features << @feature
    @site.touch
    redirect_path = sites_path
  end
  if params[:tag_id]
    @tag = Tag.find params[:tag_id]
    authorize! :create_feature, @tag
    @tag.features << @feature
    @tag.touch
    redirect_path = tags_path
  end

  if (@city && @city.save) || (@site && @site.save) || (@tag && @tag.save)
    flash[:notice] = 'Success.'
    redirect_to redirect_path
  else
    flash[:alert] = "No luck: #{pp_errors @feature.errors.messages}"
    render :action => :new
  end
end

#destroyObject



128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'app/controllers/ish_manager/features_controller.rb', line 128

def destroy
  if params[:tag_id]
    @resource = Tag.find params[:tag_id]
  elsif params[:city_id]
    @resource = City.find params[:city_id]
  elsif params[:site_id]
    @resource = Site.find params[:site_id]
  end
  authorize! :destroy_feature, @resource
  @feature = @resource.features.find params[:id]
  authorize! :destroy, @feature

  if @feature.destroy
    @resource.touch
    flash[:notice] = 'Success.'
  else
    flash[:alert] = "No luck. " + @feature.errors.messages
  end
  redirect_to request.referrer
end

#editObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'app/controllers/ish_manager/features_controller.rb', line 55

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

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

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

end

#indexObject



117
118
119
120
121
122
123
124
125
126
# File 'app/controllers/ish_manager/features_controller.rb', line 117

def index
  if params[:tag_id]
    @resource = Tag.find params[:tag_id]
  end
  if params[:site_id]
    @resource = Site.find params[:site_id]
  end
  authorize! :features_index, @resource
  @features = @resource.features
end

#newObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/controllers/ish_manager/features_controller.rb', line 6

def new
  if params[:city_id]
    @city = City.find params[:city_id]
    authorize! :new_feature, @city
  elsif params[:site_id]
    @site = Site.find params[:site_id]
    authorize! :new_feature, @site
  elsif params[:tag_id]
    @tag = Tag.find params[:tag_id]
    authorize! :new_feature, @tag
  end

  @feature = Feature.new
end

#updateObject



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'app/controllers/ish_manager/features_controller.rb', line 82

def update
  unless params[:city_id].blank?
    @city = City.find params[:city_id] 
    authorize! :update_feature, @city
    @feature = @city.features.find params[:id]
    redirect_path = city_path( @city )
  end
  unless params[:site_id].blank?
    @site = Site.find params[:site_id] 
    authorize! :update_feature, @site
    @feature = @site.features.find params[:id]
    redirect_path = site_path( @site )
  end
  unless params[:tag_id].blank?
    @tag = Tag.find params[:tag_id]
    authorize! :update_feature, @tag
    @feature = @tag.features.find params[:id]
    redirect_path = tag_path( @tag )
  end
  
  authorize! :update, @feature

  if @feature.update_attributes params[:feature].permit!
    @city.touch if @city
    @site.touch if @site
    @tag.touch  if @tag

    flash[:notice] = 'updated feature'
    redirect_to redirect_path
  else
    flash[:alert] = 'No Luck. ' + @feature.errors.messages
    render :action => :edit
  end    
end