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

Gave crud the notion of redirect paging. #2101

Merged
merged 1 commit into from
Jan 7, 2013
Merged

Gave crud the notion of redirect paging. #2101

merged 1 commit into from
Jan 7, 2013

Conversation

parndt
Copy link
Member

@parndt parndt commented Dec 29, 2012

Fixes #1861

@parndt parndt mentioned this pull request Dec 29, 2012
@parndt
Copy link
Member Author

parndt commented Dec 29, 2012

Also includes a hefty crud refactor.

@@ -184,6 +145,15 @@ def paginate_all_#{plural_name}
@#{plural_name} = @#{plural_name}.paginate(:page => params[:page], :per_page => per_page)
end

def redirect_url
if (page = params[:page]).present? && (page = page.to_i rescue 1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the point of having the to_i rescue 1 in the conditional? Won't that always return truthy?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make page 1 the default page

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but since the default is truthy it's an irrelevant part of an &&. You could instead write:

if params[:page].present?
  page = params[:page].to_i rescue 1
  page -= ...

This would lead to a much less confusing conditional since there's no need to set the page variable in it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly, but good enough.

ugisozols added a commit that referenced this pull request Jan 7, 2013
Gave crud the notion of redirect paging.
@ugisozols ugisozols merged commit ad8cea8 into master Jan 7, 2013
@ugisozols ugisozols deleted the issue_1861 branch January 7, 2013 06:08
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.

Feature deleting images
4 participants