From e18ab48a3b965b2acea5f56a6a6b4c82fcfa4d71 Mon Sep 17 00:00:00 2001 From: Raghu Betina Date: Mon, 28 Nov 2016 02:37:49 -0500 Subject: [PATCH] Final tweaks --- app/controllers/venues_controller.rb | 4 ++-- app/models/dish.rb | 3 +-- app/models/venue.rb | 4 ++-- app/views/bookmarks/edit.html.erb | 2 +- app/views/bookmarks/new.html.erb | 2 +- app/views/dishes/index.html.erb | 8 +++++++- app/views/dishes/show.html.erb | 2 +- app/views/venues/index.html.erb | 13 ++++++++++++- app/views/venues/show.html.erb | 9 ++++----- 9 files changed, 31 insertions(+), 16 deletions(-) diff --git a/app/controllers/venues_controller.rb b/app/controllers/venues_controller.rb index 2087ddc..1f34111 100644 --- a/app/controllers/venues_controller.rb +++ b/app/controllers/venues_controller.rb @@ -1,6 +1,6 @@ class VenuesController < ApplicationController def index - @q = Venue.ransack(params[:q]) + @q = current_user.bookmarked_venues.ransack(params[:q]) @venues = @q.result(:distinct => true).includes(:bookmarks, :neighborhood, :fans, :specialties).page(params[:page]).per(100) @location_hash = Gmaps4rails.build_markers(@venues.where.not(:address_latitude => nil)) do |venue, marker| marker.lat venue.address_latitude @@ -38,7 +38,7 @@ def create case referer when "/venues/new", "/create_venue" - redirect_to("/venues") + redirect_to("/dishes") else redirect_back(:fallback_location => "/", :notice => "Venue created successfully.") end diff --git a/app/models/dish.rb b/app/models/dish.rb index aed7345..c435ea1 100644 --- a/app/models/dish.rb +++ b/app/models/dish.rb @@ -19,8 +19,7 @@ class Dish < ApplicationRecord # Validations - validates :name, :uniqueness => true + validates :name, :uniqueness => { :case_sensitive => false } validates :name, :presence => true - end diff --git a/app/models/venue.rb b/app/models/venue.rb index 68b6c9e..c36c9df 100644 --- a/app/models/venue.rb +++ b/app/models/venue.rb @@ -1,5 +1,5 @@ class Venue < ApplicationRecord - before_save :geocode_address + before_validation :geocode_address def geocode_address if self.address.present? @@ -38,7 +38,7 @@ def geocode_address # Validations - validates :name, :uniqueness => { :scope => [:neighborhood_id], :message => "already exists" } + validates :name, :uniqueness => { :scope => [:address_formatted_address], :message => "already exists", :case_sensitive => false } validates :name, :presence => true diff --git a/app/views/bookmarks/edit.html.erb b/app/views/bookmarks/edit.html.erb index 0a978da..6a575c2 100644 --- a/app/views/bookmarks/edit.html.erb +++ b/app/views/bookmarks/edit.html.erb @@ -33,7 +33,7 @@ Venue - <%= select_tag(:venue_id, options_from_collection_for_select(Venue.all, :id, :name, @bookmark.venue_id), :class => "form-control") %> + <%= select_tag(:venue_id, options_from_collection_for_select(Venue.order(:name), :id, :name, @bookmark.venue_id), :class => "form-control") %> diff --git a/app/views/bookmarks/new.html.erb b/app/views/bookmarks/new.html.erb index 27e3d90..f0bb574 100644 --- a/app/views/bookmarks/new.html.erb +++ b/app/views/bookmarks/new.html.erb @@ -33,7 +33,7 @@ Venue - <%= select_tag(:venue_id, options_from_collection_for_select(Venue.all, :id, :name, @bookmark.venue_id), :class => "form-control") %> + <%= select_tag(:venue_id, options_from_collection_for_select(Venue.order(:name), :id, :name, @bookmark.venue_id), :class => "form-control") %> diff --git a/app/views/dishes/index.html.erb b/app/views/dishes/index.html.erb index e791958..4120f15 100644 --- a/app/views/dishes/index.html.erb +++ b/app/views/dishes/index.html.erb @@ -76,7 +76,7 @@ Venue - <%= select_tag(:venue_id, options_from_collection_for_select(Venue.all, :id, :name), :class => "form-control input-sm", :prompt => "Choose a venue...") %> + <%= select_tag(:venue_id, options_from_collection_for_select(Venue.order(:name), :id, :name), :class => "form-control input-sm", :prompt => "Choose a venue...") %>