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 random story endpoint #65
Conversation
@@ -6,6 +6,11 @@ class Api::StoriesController < Api::BaseController | |||
|
|||
filter_resources_by :series_id, :account_id | |||
|
|||
def random | |||
@story = Story.published.limit(1).order("RAND()")[0] |
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.
Prefer single-quoted strings when you don't need string interpolation or special symbols.
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.
can we call first
instead of [0]
? is that preferable or not? Not sure.
@eveadele happy to merge once you address the hound comments and my own. @kookster see anything you're concerned about here? I think it's a reasonable standard to set, potentially with a similar interface for accounts. I do wonder whether this justifies another link, though I am not clear how we would want to encode it. |
|
||
collection do | ||
get 'random', to: 'stories#random' | ||
end |
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.
seems like the to:
is unnecessary, perhaps just this?
get 'random', on: :collection
'api/v1/stories/random' selects a random published story. The Category Recorder app relies on this feature.