Class: IshManager::CitiesController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

#home

Instance Method Details

#change_profile_picObject



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'app/controllers/ish_manager/cities_controller.rb', line 69

def change_profile_pic
  authorize! :update, City
  @city = City.find params[:id]
  @photo = Photo.new params[:photo]
  @photo.user = @current_user
  flag = @photo.save
  @city.profile_photo = @photo
  flagg = @city.save
  if flag && flagg
    flash[:notice] = 'Success'
  else
    flash[:alert] = "No Luck. #{@photo.errors.messages} #{@city.errors.messages}"
  end
  redirect_to cities_path
end

#createObject



31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/controllers/ish_manager/cities_controller.rb', line 31

def create
  @city = City.new params[:city].permit!
  authorize! :create, @city

  if @city.save
    flash[:notice] = 'Success'
    redirect_to cities_path
  else
    flash[:alert] = 'No Luck'
    render :action => :new
  end
end

#deleteObject



85
86
87
88
89
90
91
92
# File 'app/controllers/ish_manager/cities_controller.rb', line 85

def delete
  c = City.find params[:id]
  if c.delete
    render
  else
    flash[:error] = c.errors.messages
  end
end

#editObject



44
45
46
# File 'app/controllers/ish_manager/cities_controller.rb', line 44

def edit
  authorize! :edit, @city
end

#indexObject



5
6
7
8
9
10
# File 'app/controllers/ish_manager/cities_controller.rb', line 5

def index
  authorize! :index, City
  @cities = City.unscoped
  @city = City.new
  @photo = Photo.new
end

#newObject



24
25
26
27
28
29
# File 'app/controllers/ish_manager/cities_controller.rb', line 24

def new
  @city = City.new
  authorize! :new, City

  @photo = Photo.new
end

#showObject



12
13
14
15
16
17
18
19
20
21
22
# File 'app/controllers/ish_manager/cities_controller.rb', line 12

def show
  authorize! :show, @city
  @videos = @city.videos.page( params[:videos_page] ).per( Video::PER_PAGE )
  @venues = @city.venues.page( params[:venues_page] ).per( Venue::PER_PAGE )
  @galleries = @city.galleries.page( params[:galleries_page] ).per( Gallery::PER_PAGE )
  @reports = @city.reports.page( params[:reports_page] ).per( Report::PER_PAGE )
  @newsitems = @city.newsitems.page( params[:newsitems_page] ).per( Newsitem::PER_PAGE )
  if params[:q]
    @venues = @venues.where({ :name => /#{params[:q]}/i })
  end
end

#updateObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'app/controllers/ish_manager/cities_controller.rb', line 48

def update
  @city = City.find( params[:id] )
  authorize! :update, @city
  @city.update_attributes params[:city].permit!
  if params[:photo]
    photo = Photo.new :photo => params[:photo]
    @city.profile_photo = photo
  end
  if @city.save
    ::IshModels::CacheKey.one.update_attributes( :cities => Time.now, :feature_cities => Time.now )
    flash[:notice] = 'Success'
    redirect_to city_path @city.id
  else
    flash[:alert] = 'No Luck. ' + @city.errors.inspect
    @newsitems = @city.newsitems.all.page( params[:newsitems_page] )
    @features = @city.features.all.page( params[:features_page] )
    @photo = Photo.new
    render :action => :edit
  end
end