Skip to content

Instantly share code, notes, and snippets.

@Verkalets
Created October 29, 2014 13:09
Show Gist options
  • Save Verkalets/7faf01ad2b03a88b7e3b to your computer and use it in GitHub Desktop.
Save Verkalets/7faf01ad2b03a88b7e3b to your computer and use it in GitHub Desktop.
class CitiesController < ApplicationController
before_action :set_city, only: [:show, :edit, :update, :destroy, :map_cities, :blog_cities]
load_and_authorize_resource param_method: :my_sanitizer
# GET /cities
# GET /cities.json
def index
@cities = City.all
@deals = Hotel.where(deals: true).where(published: true).limit(3)
@cities_by_rating = City.asc(:rating).limit(3)
@hotels = Hotel.where(published: true).asc(:rating).limit(3)
@homepage_element = Homepage.last
@homeimg = Homeimg.last
end
def guides
@cities = City.all.page(params[:page]).per(15)
@blogs = Blog.where(:blog_category_id => params[:id]).all
@blogs_guides = Blog.all.page(params[:page]).per(3)
@blog_categories = BlogCategory.all
@blog_comments = BlogComment.where(:blog_comment_id => params[:id]).all
@popular_blogs = Blog.all.order_by(blog_comments: :desc).limit(3)
@popular_cities = City.all.order_by(places: :desc).limit(7)
@city_first = City.all.order_by(places: :desc).limit(1)
@hash = Gmaps4rails.build_markers(@cities) do |user, marker|
marker.lat user.lat
marker.lng user.lng
end
end
def blog_guides
@cities = City.all.page(params[:page]).per(15)
@blogs = Blog.where(:blog_category_id => params[:id]).all
@blogs_guides = Blog.all.page(params[:page]).per(3)
@blog_categories = BlogCategory.all
@blog_comments = BlogComment.where(:blog_comment_id => params[:id]).all
@popular_blogs = Blog.all.order_by(blog_comments: :desc).limit(3)
@popular_cities = City.all.order_by(places: :desc).limit(7)
@city_first = City.all.order_by(places: :desc).limit(1)
@hash = Gmaps4rails.build_markers(@cities) do |user, marker|
marker.lat user.lat
marker.lng user.lng
end
end
def map_guides
@cities = City.all.page(params[:page]).per(15)
@blogs = Blog.where(:blog_category_id => params[:id]).all
@blog_categories = BlogCategory.all
@blog_comments = BlogComment.where(:blog_comment_id => params[:id]).all
@popular_blogs = Blog.all.order_by(blog_comments: :desc).limit(3)
@popular_cities = City.all.order_by(places: :desc).limit(7)
@city_first = City.all.order_by(places: :desc).limit(1)
@hash = Gmaps4rails.build_markers(@cities) do |user, marker|
marker.lat user.lat
marker.lng user.lng
end
end
# GET /cities/1
# GET /cities/1.json
def show
@blogs = Blog.where(:blog_category_id => params[:id]).all
@blogs_all = Blog.all.page(params[:page]).per(3)
@blog_categories = BlogCategory.all
@blog_comments = BlogComment.where(:blog_comment_id => params[:id]).all
@popular_blogs = Blog.all.order_by(blog_comments: :desc).limit(3)
@cities = City.all
@places = @city.places.page(params[:page]).per(15)
@hash = Gmaps4rails.build_markers(@places) do |user, marker|
marker.lat user.lat
marker.lng user.lng
end
end
def blog_cities
@blogs = Blog.where(:blog_category_id => params[:id]).all
@blogs_all = Blog.all.page(params[:page]).per(3)
@blog_categories = BlogCategory.all
@blog_comments = BlogComment.where(:blog_comment_id => params[:id]).all
@popular_blogs = Blog.all.order_by(blog_comments: :desc).limit(3)
@cities = City.all
#@places = @city.places.page(params[:page]).per(15)
@hash = Gmaps4rails.build_markers(@places) do |user, marker|
marker.lat user.lat
marker.lng user.lng
end
end
def map_cities
@blogs = Blog.where(:blog_category_id => params[:id]).all
@blog_categories = BlogCategory.all
@blog_comments = BlogComment.where(:blog_comment_id => params[:id]).all
@popular_blogs = Blog.all.order_by(blog_comments: :desc).limit(3)
@cities = City.all
@places = @city.places.page(params[:page]).per(15)
@hash = Gmaps4rails.build_markers(@places) do |user, marker|
marker.lat user.lat
marker.lng user.lng
end
end
# GET /cities/admin
def admin
@cities = City.all
@places = Place.all
@hash = Gmaps4rails.build_markers(@cities) do |user, marker|
marker.lat user.lat
marker.lng user.lng
end
end
def user_admin
@cities = City.all
@hotels = Hotel.all
@places = Place.all
@hash = Gmaps4rails.build_markers(@cities) do |user, marker|
marker.lat user.lat
marker.lng user.lng
end
end
# GET /cities/new
def new
@city = City.new
end
# GET /cities/1/edit
def edit
end
def order_sent
@checkout = Checkout.find(session[:checkout_id])
end
# POST /cities
# POST /cities.json
def create
#@city = current_user.cities.new(city_params)
#@city.user_email = current_user.email
@city = City.new(city_params)
respond_to do |format|
if @city.save
format.html { redirect_to @city, notice: 'City was successfully created.' }
format.json { render action: 'show', status: :created, location: @city }
else
format.html { render action: 'new' }
format.json { render json: @city.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /cities/1
# PATCH/PUT /cities/1.json
def update
if params[:delete_image]
@city.remove_cityimg
end
respond_to do |format|
if @city.update(city_params)
format.html { redirect_to @city, notice: 'City was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: 'edit' }
format.json { render json: @city.errors, status: :unprocessable_entity }
end
end
end
def destroy
@city.destroy
respond_to do |format|
format.html { redirect_to action: 'admin' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_city
@city = City.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def city_params
params.require(:city).permit(:name, :hotel_id, :description, :user_email, :place_id, :cityimg, :total, :density, :ethnicities, :religions, :country)
end
def my_sanitizer
params.require(:city).permit(:name)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment