0

Ok, I sorta get it and I sorta don't.

I see a lot of statements like this:

scope :tutor_role, ->{with_role("tutor")}
scope :chapter_leader_role, ->{with_role("chapter_leader")}
scope :teacher_role, ->{with_role("teacher")} 

My basic understanding of using scope as written above is that it's a way to limit the data retrieved from the database, ie, very specific data.

Is that a correct understanding of scopes?

EDIT

Before anyone else comments that this is a duplicate again, and I don't necessarily disagree with that assessment, there were several reasons why I had asked this question.

One of the reasons why I had stuck that example code in this post is that I was also confused about "with_role" in the context of the scope statements.

What is that? I didn't see that in other scoping questions, hence I thought I would go ahead with this question.

user273072545345
  • 1,536
  • 2
  • 27
  • 57
  • @vee, I can see why you would think this is a duplicate. The difference, at least for me, is that you see "with_role" in my post? what is that? what is the context for using that in scopes? I don't see that in other scopes question. – user273072545345 Apr 07 '14 at 18:49
  • 2
    `with_role` is specific to your application. It's either a scope like `scope :with_role, ->(role) { where(role: role) }`, or a class method returning a relation. – Robin Apr 07 '14 at 18:56
  • @Robin, hm, I'd have to think about what you said. Not sure if I quite get it. Was at least my basic understanding as written in my post at least correct? – user273072545345 Apr 07 '14 at 19:00
  • @vee, Ok, thanks. Guess I need to poke further around in the application that I got this from. – user273072545345 Apr 07 '14 at 19:01
  • http://apidock.com/rails/ActiveRecord/Scoping/Named/ClassMethods/scope – Fred Apr 07 '14 at 21:00

0 Answers0