named-scope

Rails gem rails3-jquery-autocomplete how to scope by user

眉间皱痕 提交于 2019-11-27 23:07:51
I'm using the Rails gem rails3-jquery-autocomplete to add categories to posts. I would like to restrict the search to include only categories that belong to the current user or post's author in the results. The documentation says that I can specify a scope: :scopes Added option to use scopes. Pass scopes in an array. e.g :scopes => [:scope1, :scope2] But I'm not sure how I would pass the user id here? It seems like a comon scenario, am I missing something obvious? I found an answer that suggests modifying the get_item method, but that seems to break the auto-complete Scoping the results for

Rails: Is that possible to define named scope in a module?

时光怂恿深爱的人放手 提交于 2019-11-27 11:35:50
问题 Say there are 3 models: A, B, and C. Each of these models has the x attribute. Is that possible to define a named scope in a module and include this module in A, B, and C ? I tried to do so and got an error message saying that scope is not recognized... 回答1: Yes it is module Foo def self.included(base) base.class_eval do scope :your_scope, lambda {} end end end 回答2: As of Rails 3.1 the syntax is simplified a little by ActiveSupport::Concern: Now you can do require 'active_support/concern'

What is scope/named_scope in rails?

柔情痞子 提交于 2019-11-27 10:04:45
I've recently started an internship. My employer uses ruby on rails, and I frequently encounter new syntax that I need to look up to understand. I've googled around for a good explanation of named_scope, but what I've found so far is mostly blog posts giving high praise for it, rather a straight definition or introduction. What exactly is named_scope (now simply called scope) in ruby on rails? Michael Schäfermeyer A scope is a subset of a collection. Sounds complicated? It isn't. Imagine this: You have Users. Now, some of those Users are subscribed to your newsletter. You marked those who