Questions tagged [has-scope]

has_scope is a Ruby gem that allows you to easily create controller filters based on your resources named scopes.

has_scope is a Ruby gem that allows you to easily create controller filters based on your resources named scopes.

31 questions
1
vote
1 answer

rails has_scope and sphinx search

In my application I use has_scope gem and thinking sphinx, and in model I have written something like: scope :by_description, -> description { where("description like ?", "%#{description}%") if description.present?} and then, In…
brabertaser19
  • 5,678
  • 16
  • 78
  • 184
1
vote
1 answer

Filtering Rails Controllers Actions from Query Params

I'm looking for the best method for filtering the records I return to a view in Rails, based on an arbitrary amount of query parameters, e.g: http://localhost:3000/foo?some_field=fubar&this_field_left_blank=&a_third_field=bar What I'm currently…
xyzjace
  • 432
  • 1
  • 5
  • 16
0
votes
1 answer

Using has_scope to filter by nested attributes in a HABTM relationship

I have an API in which i have a HABTM relationship between Characters and Movies (a movie has many characters and a character has many movies). I'm trying to set up a filter with has_scope gem so i can do something…
GuidoMedina
  • 117
  • 1
  • 9
0
votes
1 answer

How can I optimise this active record query in this filterable, paginated rails API?

I'm building a Rails API from a model Service with several nested relations (many-to-one and many-to-many). The basic index route has a fast enough response time (~150ms), but when I add a filter query to the URL (eg…
0
votes
1 answer

Display the active filter using has_scope gem Rails

I have a Entry model that has_many courses through entry_courses (has_many through association). I've set up my scope as such in my entry.rb (model) scope :by_courses, -> (ids_ary) { joins(entry_courses: :course).where("courses.id" =>…
chris
  • 61
  • 1
  • 7
0
votes
1 answer

Filter objects with many-to-many table in Rails using has_scope

There are two tables: User and Industry. User can relate to many industries and a lot of users belong to one Industry. Industry.rb class Industry : industry_users     has_many:…
zshanabek
  • 4,270
  • 3
  • 19
  • 27
0
votes
0 answers

Rails 4 has_scope throwing undefined method error

Having a similar issue to this guy: Rails 4 with has_scope: fails silently But his answer didn't help my situation. I'm using the has_scope gem with the following code: #model class Inbox < ActiveRecord::Base has_paper_trail has_many :requests …
Evan Lemmons
  • 807
  • 3
  • 11
  • 27
0
votes
2 answers

.current_user not working when using scopes?

I'm using Devise and has_scope gem for filtering options and only want show a current users links only. This works @links = current_user.links.all This does not. Can someone explain what i need to do to make this work? @links =…
EliteViper777
  • 101
  • 10
0
votes
1 answer

Filter index with has_scope gem and collection_select

I've got a two models: Business and Category. In my business#index view, all Business names are displayed in a table, along with their associated Category. I'm using the has_scope gem and added two scopes to my Business model: :by_category and…
K.C. Barrett
  • 152
  • 1
  • 9
0
votes
1 answer

Error in installing ActiveAdmin gem in rails 4

This is the error after I run bundle install in rails. I'm using rails 4. I already followed the instruction that given but nothings happen. Gem::RemoteFetcher::UnknownHostError: no such name (https://rubygems.org/gems/has_scope-0.6.0.rc.gem) An…
0
votes
1 answer

How do allow to use a scope only to admin users with a certain value in Rails 4 model?

In my recent Rails project I have a scope in a model. This scope has two possible values: true or false. scope :ultima, -> ultima { where(:ultima => ultima ) I´m using has_scope gem to allow using this scope in controller so I can do calls like…
Marino
  • 106
  • 9
0
votes
1 answer

Rails - How can I use has_scope with collection_select?

I'm new to rails and I'm using the has_scope gem to help me filter a list to display as a table. I have the has_scope gem setup fine and working for basic parameters (search string, etc.) How can I get has_scope to recognize the parameters passed in…
Major Major
  • 2,697
  • 3
  • 27
  • 35
0
votes
1 answer

Using rails has_scope gem to scope the last x number of items in array

I'm using the has_scope gem. I want to scope the last x number of items in an array of Articles in my database something like this: scope :last_few_items, -> num { Article.last(num) } so in my querystring I could say www.bla.com?last_few_items=2 to…
rikkitikkitumbo
  • 954
  • 3
  • 17
  • 38
0
votes
2 answers

Rails has_scope gem used on nil param

In my app I'm using has_scope gem. I have made some scope they are working to find a string in a field. But now I would add a new scope to find all records where a specific param is nil How to do that ? I'm unable to find the right syntax, now I…
Nicolas R
  • 55
  • 6
0
votes
1 answer

Rails: multiple params (filter) with has_scope

I'm using has_scope gem and I want to create filtering with two params — it may be one param or two same time. Mymodel (Product): scope :brand, proc { |brand| joins(:product_values).where('product_values.value_id' => brand) } scope :zamena, proc {…
Oleg Pasko
  • 2,831
  • 5
  • 35
  • 44