Questions tagged [named-scope]
339 questions
0
votes
1 answer
Rails 3 rails3-jquery-autocomplete search by several fields
I am using rails3-jquery-autocomplete plugin.
I would like to search by several attributes, for instance title and app_number.
What I tried:
in model:
class Eclaim < ActiveRecord::Base
scope :search_by_number, ->(query){
(query ?…

Lesha Pipiev
- 3,251
- 4
- 31
- 65
0
votes
1 answer
Rails 3 - Create a scope that takes advantage of a method
In my model I would like to create a scope that takes advantage of a method that is also in my model.
I have the following model method:
def is_paired
! pairing_id.nil?
end
I would like to make a scope that looks something like this
scope…

Selah
- 7,728
- 9
- 48
- 60
0
votes
1 answer
Custom Model Method, setting scope for automatic sending of mail
There are several stages to this, and as I am relatively new to rails I am unsure if I am approaching this in the best way.
Users follow Firms, Firms applications open and close on certain days. If a user follows a firm I would like them to…

RMcNairn
- 491
- 1
- 5
- 20
0
votes
2 answers
ActiveRecord conditions of an association (Rails)
Pretend I have a model, Post which has_many :comments. How can I only display posts that have comments?
I am somewhat comfortable with named_scope but I don't know how I can put Post.comments (or self.comments) in the :conditions hash which expects…

user94154
- 16,176
- 20
- 77
- 116
-1
votes
1 answer
Regular expression in Rails scope not capturing the right values
I would like to capture rows with "0" when I have values such as this:
"0,1,8,9,10"
"10"
"0,1"
"4,5"
"1,5,10"
The code that I inherited was capturing values both "0" and "10" which is wrong:
scope :short_result_contains_value, -> (game_id,…

MLZ
- 403
- 7
- 20
-1
votes
2 answers
How to sum columns and group by date column in Rails
I have a model with following columns
Charges Model
Date
fee
discount
Data
1/1/15, 1, 1
1/1/15, 2, 1
2/2/15, 3, 3
I have a few named scopes like this_year
I want to do something like Charges.this_year.summed_up
How do I make a named scope for…

whizcreed
- 2,700
- 3
- 22
- 35
-1
votes
2 answers
Can I make this Rails 4 named scope nicer
I believe this is called a named scope, if I am not mistaken. At any rate, does anyone know of a better / more efficient way of coding this..
This is from a Rails 4 Model
def line_total
product = Product.find_by_id(self.product_id)
line_total…

Jakcst
- 605
- 3
- 8
- 16
-1
votes
2 answers
rails scope model without relation
I have such model
class Ads::Posting < ActiveRecord:Base
has_one :child, class_name: 'Ads::Posting', foreign_key: :posting_id
belongs_to :parent, class_name: 'Ads::Posting', foreign_key: :posting_id
end
I need to write scope which gets all…

jizak
- 382
- 2
- 13
-2
votes
1 answer
Link_to a named scope with attribute
After an afternoon spending in web search. I have to ask you.
In my app I have a list of games which have one or more platforms associated. I want to propose to the user some filter based on the platform.
I know that I have to use named scopes with…

NotGrm
- 111
- 1
- 8