Files
grecia/app/controllers/admin/geozones_controller.rb
Javi Martín 16c16e3cdf Mark safe SQL with Arel.sql
Rails 5.2 is raising a warning in some places:

DEPRECATION WARNING: Dangerous query method (method whose arguments are
used as raw SQL) called with non-attribute argument(s). Non-attribute
arguments will be disallowed in Rails 6.0. This method should not be
called with user-provided values, such as request parameters or model
attributes. Known-safe values can be passed by wrapping them in
Arel.sql().

IMHO this warning is simply wrong, since we're using known PostgreSQL
functions like LOWER() or RANDOM(). AFAIK this code works without warnings
in Rails 6.0 [1][2]

However, since the warning is annoying, we need to take measures so our
logs are clean.

[1] https://github.com/rails/rails/commit/6c82b6c99d
[2] https://github.com/rails/rails/commit/64d8c54e16
2020-10-15 14:57:42 +02:00

49 lines
922 B
Ruby

class Admin::GeozonesController < Admin::BaseController
respond_to :html
load_and_authorize_resource
def index
@geozones = Geozone.all.order(Arel.sql("LOWER(name)"))
end
def new
end
def edit
end
def create
@geozone = Geozone.new(geozone_params)
if @geozone.save
redirect_to admin_geozones_path
else
render :new
end
end
def update
if @geozone.update(geozone_params)
redirect_to admin_geozones_path
else
render :edit
end
end
def destroy
if @geozone.safe_to_destroy?
@geozone.destroy!
redirect_to admin_geozones_path, notice: t("admin.geozones.delete.success")
else
redirect_to admin_geozones_path, flash: { error: t("admin.geozones.delete.error") }
end
end
private
def geozone_params
params.require(:geozone).permit(:name, :external_code, :census_code, :html_map_coordinates)
end
end