Skip to content

Commit 0d4065f

Browse files
committed
Updated old model scopes definition
1 parent cbcd84a commit 0d4065f

File tree

4 files changed

+16
-16
lines changed

4 files changed

+16
-16
lines changed

app/models/message.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ class Message < ActiveRecord::Base
44
belongs_to :service
55
belongs_to :status
66

7-
scope :with_status, lambda { |status_id|
7+
scope :with_status,-> (status_id) {
88
where(status_id: status_id)
99
}
1010
end

app/models/service_request.rb

+10-10
Original file line numberDiff line numberDiff line change
@@ -21,41 +21,41 @@ class ServiceRequest < ActiveRecord::Base
2121
mount_uploader :media, ImageUploader
2222
acts_as_voteable
2323

24-
default_scope order: 'created_at DESC'
24+
default_scope { order('created_at DESC') }
2525

26-
scope :on_start_date, lambda {|from|
26+
scope :on_start_date, -> (from) {
2727
where("service_requests.created_at >= ?", from) unless from.blank?
2828
}
2929

30-
scope :on_finish_date, lambda { |to|
30+
scope :on_finish_date, -> (to) {
3131
where("service_requests.created_at <= ?", to) unless to.blank?
3232
}
3333

34-
scope :with_status, lambda { |status_id|
34+
scope :with_status, -> (status_id) {
3535
where(status_id: status_id) unless status_id.blank?
3636
}
3737

38-
scope :on_status_name, lambda { |status_name|
38+
scope :on_status_name, -> (status_name) {
3939
joins(:status).where('statuses.name = ?', status_name) unless status_name.blank?
4040
}
4141

42-
scope :on_service, lambda { |service_ids|
42+
scope :on_service, -> (service_ids) {
4343
where(service_id: service_ids.split(',')) unless service_ids.blank?
4444
}
4545

46-
scope :find_by_ids, lambda { |ids|
46+
scope :find_by_ids, -> (ids) {
4747
where("service_requests.id IN (?)", ids.split(',')) unless ids.blank?
4848
}
4949

50-
scope :closed, lambda {
50+
scope :closed, -> {
5151
where(status_id: 4)
5252
}
5353

54-
scope :not_closed, lambda {
54+
scope :not_closed, -> {
5555
where('status_id != ?', 4)
5656
}
5757

58-
scope :open, lambda {
58+
scope :open, -> {
5959
where(status: 1)
6060
}
6161

app/models/status.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class Status < ActiveRecord::Base
77

88
before_create :set_default_if_is_the_first
99

10-
default_scope order('created_at')
10+
default_scope { order('created_at') }
1111

1212
def to_s
1313
name

app/models/vote.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
class Vote < ActiveRecord::Base
22

3-
scope :for_voter, lambda { |*args| where(["voter_id = ? AND voter_type = ?", args.first.id, args.first.class.base_class.name]) }
4-
scope :for_voteable, lambda { |*args| where(["voteable_id = ? AND voteable_type = ?", args.first.id, args.first.class.base_class.name]) }
5-
scope :recent, lambda { |*args| where(["created_at > ?", (args.first || 2.weeks.ago)]) }
6-
scope :descending, order("created_at DESC")
3+
scope :for_voter, -> (*args) { where(["voter_id = ? AND voter_type = ?", args.first.id, args.first.class.base_class.name]) }
4+
scope :for_voteable, -> (*args) { where(["voteable_id = ? AND voteable_type = ?", args.first.id, args.first.class.base_class.name]) }
5+
scope :recent, -> (*args) { where(["created_at > ?", (args.first || 2.weeks.ago)]) }
6+
scope :descending, -> { order("created_at DESC") }
77

88
belongs_to :voteable, :polymorphic => true
99
belongs_to :voter, :polymorphic => true

0 commit comments

Comments
 (0)