diff --git a/app/controllers/api/v1/location_machine_xrefs_controller.rb b/app/controllers/api/v1/location_machine_xrefs_controller.rb index f55a9056..fa2724b3 100644 --- a/app/controllers/api/v1/location_machine_xrefs_controller.rb +++ b/app/controllers/api/v1/location_machine_xrefs_controller.rb @@ -38,8 +38,8 @@ def create return return_response(AUTH_REQUIRED_MSG, 'errors') if user.nil? - location_id = params[:location_id] - machine_id = params[:machine_id] + location_id = params[:location_id].to_i + machine_id = params[:machine_id].to_i condition = params[:condition] status_code = 200 diff --git a/app/controllers/api/v1/location_picture_xrefs_controller.rb b/app/controllers/api/v1/location_picture_xrefs_controller.rb index 867a831f..82ca8689 100644 --- a/app/controllers/api/v1/location_picture_xrefs_controller.rb +++ b/app/controllers/api/v1/location_picture_xrefs_controller.rb @@ -21,7 +21,7 @@ def show def create return return_response(AUTH_REQUIRED_MSG, 'errors') if current_user.nil? - location_id = params[:location_id] + location_id = params[:location_id].to_i return return_response('Failed to find location', 'errors') if location_id.nil? || !Location.exists?(location_id) photo = params[:photo] diff --git a/app/models/location.rb b/app/models/location.rb index e14302fd..e3352c82 100644 --- a/app/models/location.rb +++ b/app/models/location.rb @@ -3,8 +3,8 @@ class Location < ApplicationRecord validates_presence_of :name, :street, :city, :country validates :phone, phone: { possible: true, allow_blank: true, message: 'Phone format not valid.' } - validates :website, format: { with: %r{http(s?)://}, message: 'must begin with http:// or https://' }, if: :website? - validates :name, :street, :city, format: { with: /^\S.*/, message: "Can't start with a blank", multiline: true } + validates :website, format: { with: %r{\Ahttp(s?)://}, message: 'must begin with http:// or https://' }, if: :website? + validates :name, :street, :city, format: { with: /\A\S.*/, message: "Can't start with a blank", multiline: true } validates :lat, :lon, presence: { message: 'Latitude/Longitude failed to generate. Please double check address and try again, or manually enter the lat/lon' } belongs_to :location_type, optional: true diff --git a/app/models/machine_score_xref.rb b/app/models/machine_score_xref.rb index c55b4495..6f17986a 100644 --- a/app/models/machine_score_xref.rb +++ b/app/models/machine_score_xref.rb @@ -8,8 +8,8 @@ class MachineScoreXref < ApplicationRecord scope :zone_id, lambda { |id| joins(:location_machine_xref).joins(:location).where(" - locations.zone_id = #{id} - ") + locations.zone_id = ? + ", id) } scope :region, lambda { |name| @@ -17,8 +17,8 @@ class MachineScoreXref < ApplicationRecord joins(:location_machine_xref).joins(:location).where(" location_machine_xrefs.id = machine_score_xrefs.location_machine_xref_id and locations.id = location_machine_xrefs.location_id - and locations.region_id = #{r.id} - ") + and locations.region_id = ? + ", r.id) } def username diff --git a/app/models/suggested_location.rb b/app/models/suggested_location.rb index 98e4fced..d62fb585 100644 --- a/app/models/suggested_location.rb +++ b/app/models/suggested_location.rb @@ -5,8 +5,8 @@ class SuggestedLocation < ApplicationRecord validates_presence_of :name, :machines, on: :create validates_presence_of :street, :city, :zip, on: :update - validates :website, format: { with: %r{http(s?)://}, message: 'must begin with http:// or https://' }, if: :website?, on: :update - validates :name, :street, :city, format: { with: /^\S.*/, message: "Can't start with a blank", multiline: true }, on: :update + validates :website, format: { with: %r{\Ahttp(s?)://}, message: 'must begin with http:// or https://' }, if: :website?, on: :update + validates :name, :street, :city, format: { with: /\A\S.*/, message: "Can't start with a blank", multiline: true }, on: :update validates :lat, :lon, presence: { message: 'Latitude/Longitude failed to generate. Please double check address and try again, or manually enter the lat/lon' }, on: :update belongs_to :region, optional: true @@ -97,19 +97,21 @@ def convert_to_location(user_email) delete - ActiveRecord::Base.connection.execute(<