Skip to content
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

Merged
merged 4 commits into from Dec 18, 2014
Merged

Add random story endpoint #65

merged 4 commits into from Dec 18, 2014

Conversation

eveadele
Copy link
Contributor

'api/v1/stories/random' selects a random published story. The Category Recorder app relies on this feature.

@@ -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]

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.

Copy link
Contributor

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.

@cqr
Copy link
Contributor

cqr commented Dec 15, 2014

@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
Copy link
Member

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

kookster added a commit that referenced this pull request Dec 18, 2014
@kookster kookster merged commit ade2452 into master Dec 18, 2014
@kookster kookster deleted the feat/random_story branch December 18, 2014 18:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants