diff --git a/app/controllers/related_contents_controller.rb b/app/controllers/related_contents_controller.rb index 06bfaadc7..1ea9e02f9 100644 --- a/app/controllers/related_contents_controller.rb +++ b/app/controllers/related_contents_controller.rb @@ -22,21 +22,19 @@ class RelatedContentsController < ApplicationController end def relationable_object - @relationable = (params[:relationable_klass].singularize.camelize.constantize).find_by_id(params[:relationable_id]) + @relationable = params[:relationable_klass].singularize.camelize.constantize.find_by(id: params[:relationable_id]) end def related_object - begin if valid_url? url = params[:url] - related_klass = url.match(/\/(#{RelatedContent::RELATIONABLE_MODELS.join("|")})\//)[0].gsub("/", "") - related_id = url.match(/\/[0-9]+/)[0].gsub("/", "") + related_klass = url.match(/\/(#{RelatedContent::RELATIONABLE_MODELS.join("|")})\//)[0].delete("/") + related_id = url.match(/\/[0-9]+/)[0].delete("/") - @related = (related_klass.singularize.camelize.constantize).find_by_id(related_id) + @related = related_klass.singularize.camelize.constantize.find_by(id: related_id) end - rescue + rescue nil - end end end diff --git a/app/models/concerns/notifiable.rb b/app/models/concerns/notifiable.rb index f9748c64f..b10c57f70 100644 --- a/app/models/concerns/notifiable.rb +++ b/app/models/concerns/notifiable.rb @@ -25,8 +25,8 @@ module Notifiable def check_availability(resource) resource.present? && - resource.try(:hidden_at) == nil && - resource.try(:retired_at) == nil + resource.try(:hidden_at).nil? && + resource.try(:retired_at).nil? end def linkable_resource diff --git a/app/models/related_content.rb b/app/models/related_content.rb index fa41a57ad..4fbb1f48d 100644 --- a/app/models/related_content.rb +++ b/app/models/related_content.rb @@ -1,6 +1,6 @@ class RelatedContent < ActiveRecord::Base RELATED_CONTENTS_REPORT_THRESHOLD = Setting['related_contents_report_threshold'].to_i - RELATIONABLE_MODELS = %w{proposals debates} + RELATIONABLE_MODELS = %w{proposals debates}.freeze belongs_to :parent_relationable, polymorphic: true belongs_to :child_relationable, polymorphic: true diff --git a/lib/tasks/polls.rake b/lib/tasks/polls.rake index cf10afffd..e87e171d3 100644 --- a/lib/tasks/polls.rake +++ b/lib/tasks/polls.rake @@ -1,6 +1,6 @@ namespace :polls do - desc "Adds created_at and updated_at values to existing polls" - task initialize_timestamps: :environment do - Poll.update_all(created_at: Time.current, updated_at: Time.current) - end + desc "Adds created_at and updated_at values to existing polls" + task initialize_timestamps: :environment do + Poll.update_all(created_at: Time.current, updated_at: Time.current) + end end