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
8
votes
1 answer

"Not equal" named scope in rails with Mongoid

I have two models Content and ContentType. In Content model I can do: def get_all_content_except_poking_message Content.all.where(:name.ne => "no forking, just poking") end Now, I am trying to apply scope on ContentType. In Content model again: #…
Annie
  • 3,090
  • 9
  • 36
  • 74
4
votes
1 answer

How to correctly write parameter in url when scope is array type?

I created a scope and pointed it to the array type. has_scope: by_industry,: type =>: array And now I want to make this scope working. I tried to pass parameter in url like this: http://localhost:3000/v1/find_friends?by_industry=[1,2] Does not…
zshanabek
  • 4,270
  • 3
  • 19
  • 27
3
votes
2 answers

Can I attach a named scope to a link in Rails?

I have an events model which has two named scopes: class Event < ActiveRecord::Base scope :future, lambda { where('events.date >= ?', Time.zone.now) } scope :past, lambda { where('events.date <= ?', Time.zone.now) } end I call these scopes from…
stephenmurdoch
  • 34,024
  • 29
  • 114
  • 189
3
votes
1 answer

Passing current_scopes from the has_scopes gem as a param

I've been struggling with this problem for several days. I'm a lawyer and I'm building a Q&A type site for legal advice (yups, I'm a relative newbie to rails :-)). I want users to be able to filter questions by category (i.e. company law, IP etc…
3
votes
2 answers

How to use has_scope gem in a view in rails 4?

I'm trying to add a clickable link that will sort a page of links alphabetically using has_scope gem. What exactly would i put in my view to make this work? Model Links.rb scope :abc, -> { order("links.title ASC") } Links_Controller.rb …
EliteViper777
  • 101
  • 10
3
votes
1 answer

Rails has_scope with if condition

In my form i have a lot of fields, and when i submit my form im my url i see a lot of empty params, like url?a=&b=&c= and my has_scope model think that i want to use this params, but with null value, but this is wrong. Part of my model and…
brabertaser19
  • 5,678
  • 16
  • 78
  • 184
2
votes
1 answer

How to create a form using simple_form to control scopes (via has_scope) in a view

Basically, I cannot figure out how to prevent the form generator from encapsulating everything in a hash (filter{...}), thus making it easy for the form to set the params used in the view's scoping. has_scope code in controller: has_scope…
2
votes
1 answer

Routing error with has_scope

I am getting the error below with has_scope. This seems like a really obvious and basic error but I just can't work it out. I'd really appreciate any help that can be offered. I have got ActiveAdmin elsewhere on the site and I believe that uses it…
bnussey
  • 1,894
  • 1
  • 19
  • 34
2
votes
1 answer

Include a concern module in a rails controller

Here is my concern file: controllerconcerns.rb require 'active_support/concern' module Query_scopes extend ActiveSupport::Concern has_scope :title end Here is my controller I want to include it in: api_controller.rb class ApiController <…
rikkitikkitumbo
  • 954
  • 3
  • 17
  • 38
2
votes
1 answer

How to use acts-as-taggable-on with has_scope?

I'm building an API that returns a list of posts (localhost:3000/api/v1/posts): { "tags": [ { "id": 1, "name": "Tag 1" }, { "id": 2, "name": "Tag 2" }, … ], "posts": [ { "id": 1, …
davidg
  • 651
  • 1
  • 7
  • 18
1
vote
1 answer

How can I call/use my scope in my view

I am trying to use has_scope to filter all Keys that are not connected to a Room via my KeyRoomMapping Table. I've created the scope in my Keys model, but I don't know how to call the scope in my view. Models class Key < ApplicationRecord …
Serge Pedroza
  • 2,160
  • 3
  • 28
  • 41
1
vote
1 answer

Include selected has_scope on ransack search filter

I am attempting to combine has_scope and ransack. Each of these components is working perfectly by themselves. However, when I attempt to combine them, they overwrite each other. For example, if I select a scope, the results are appropriately…
bnussey
  • 1,894
  • 1
  • 19
  • 34
1
vote
1 answer

How to use has_scope with inherited_resources?

I'm following git wiki for has_scope. It has an example: # in model scope :featured, -> whatever # in controller has_scope :by_degree ... @graduations = apply_scopes(Graduation).all So did that: class Account < ActiveRecord::Base scope…
Serge Vinogradoff
  • 2,262
  • 4
  • 26
  • 42
1
vote
1 answer

Rails 4 with has_scope: fails silently

I have a Rails 4.0.0 app and want to include the has_scope gem. Very simple and straight resources: Model: class Thing < ActiveRecord::Base resourcify ... belongs_to :client validates_presence_of :name scope :by_client, -> client {…
1
vote
3 answers

Pass current_scopes on to search

I'm using the very helpful has_scope gem. I have an index page created by passing scopes in a link. <%= user_collections_path(@user, got: true) %> On that index page I can query the current_scopes. I have a pretty standard ransack search form on…
Ossie
  • 1,103
  • 2
  • 13
  • 31
1
2 3