-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add technology parameters to jobs#index, ready for review #96
Conversation
Because technology#show is a single resource, pagination balks and throws and error at pagination. Somehow I need to point the pagination at the jobs.
I'm not positive I understand the problem, but would writing a simple scope on Job for each Technology solve this? That way you could call, for instance Job.ruby and return (and paginate?) only the Ruby jobs? Does this make sense or am I off base here? |
I think I"ll have to show you in person.(I say as you sit right next to me) |
Jobs#index now supports querying for a subset of jobs based on technology. The index action now looks to see if there's a technology parameter, then scopes the jobs response appropriately. This pattern will be a little dryer and more sustainable than what I previously was playing with. Sample query looks like: api/v1/jobs/?technology=python
Ready for review @cheljoh @NickyBobby @brennanholtzclaw |
@@ -19,4 +20,8 @@ def assign_tech | |||
tech_matches = Technology.where(name: raw_technologies) | |||
self.technologies = tech_matches | |||
end | |||
|
|||
def self.by_tech(tech_name) | |||
joins(:technologies).where(technologies: {name: tech_name}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is good! Nice "scope" you made here!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so I came across this weird note that Rails "officially" prefers class methods if you pass in a param so I shrugged and made a class method instead of a scope. But it does make me feel weird. ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. Can you make a scope that accepts an argument? I thought that's why you did it this way/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it looks like scope :created_before, ->(time) { where("created_at < ?", time) } end
(stolen from the aforementioned docs)
Hey hey it's the Monkees!
|
I approve of this giphy. |
Hey sorry I didn't get a chance to look at this until now. Does the endpoint return all jobs that match tech or does it scope by recent jobs? Might be nice to return only more recent jobs (e.g., last two months). |
I can't paginate the endpoint for individual technologies because the method sees it as an individual resource. Somehow I need to point it at the jobs, or potentially return the jobs in the first place, and include the parameter/technology name in the JSON (working on the latter, this issue seems relevant.