Sha256: b422bad24b9cbdb7ec7f0ab972741ff789170865786cb36cbc13f10e8f8995e3

Contents?: true

Size: 1.95 KB

Versions: 1

Compression:

Stored size: 1.95 KB

Contents

class IshManager::CitiesController < IshManager::ApplicationController
  before_action :set_lists, :only => [ :new_newsitem, :create_newsitem ]
  before_action :sett_city, :only => [ :show, :edit ]

  def index
    authorize! :cities_index, Manager
    @cities = City.all
    @city = City.new
    @photo = Photo.new
  end
  
  def show
    authorize! :show, @city
  end
  
  def new
    @city = City.new
    authorize! :new, City

    @photo = Photo.new
  end

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

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

  def edit
    authorize! :edit, @city
  end
  
  def update
    @city = City.find( params[:id] )
    authorize! :update, @city
    @city.update_attributes params[:city].permit!
    if @city.save
      flash[:notice] = 'Success'
      redirect_to edit_city_path @city.id
    else
      flash[:error] = '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

  def change_profile_pic
    authorize! :change_profile_pic, 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[:error] = "No Luck. #{@photo.errors.inspect} #{@city.errors.inspect}"
    end
    redirect_to cities_path
  end

  private

  def sett_city
    @city = City.find params[:id]
    @photo = Photo.new
  end

  def set_lists
    @list_reports = Report.all.list
    @list_galleries = Gallery.all.list
    @list_users = [['', nil]] + User.all.order_by( :name => :asc ).map { |u| [u.username, u.username] }
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ish_manager-0.1.8.24 app/controllers/ish_manager/cities_controller.rb