-
Notifications
You must be signed in to change notification settings - Fork 864
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
Link to first page without a param #459
Comments
In def paginate(collection, params= {})`
will_paginate collection, params.merge(:renderer => LinkPaginationHelper::LinkRenderer)
end In module LinkPaginationHelper
class LinkRenderer < WillPaginate::ActionView::LinkRenderer
def link(text, target, attributes = {})
if text == 1
return "<a rel=\"prev start\" href=\"/\">1</a>"
end
super
end
def previous_or_next_page(page, text, classname)
if page == 1
return "<a class=\"previous_page\" rel=\"prev\" href=\"/\">← Previous</a>"
end
super
end
end
end and in = paginate @posts This should overwrite the 1 page link and also the (updated the name of the class and methods) |
But how do I get the url to be categories? Because currently
redirects to / and i would like to redirect to categories/episodes/otherobject. |
You can hard code it in the link as |
I could, and other. So hard-coding it would not do. How is will_paginate detecting if it is paginating episodes or categories On 9 December 2015 at 09:11, Rishi notifications@github.com wrote:
+359 878 93 30 94 |
ahhh ok. So you can do this: in = paginate @posts, {"data-length" => 20, :controller_accessed => "posts"} in module LinkPaginationHelper
class LinkRenderer < WillPaginate::ActionView::LinkRenderer
@object_type_accessed = nil
def prepare(collection, options, template)
@object_type_accessed = options[:controller_accessed]
super
end
def link(text, target, attributes = {})
if text == 1
return "<a rel=\"prev start\" href=\"/#{@object_type_accessed}\">1</a>"
end
super
end
#same logic for `previous_or_next_page` method
end
end Let me know if this works out. |
Tried it. Didn't work. If I have an "episodes" controller with /episodes as url it works as expected. And in this case the link for first page on /categories/the_cat_name?page=2 is /categories, while it should be /categories/the_cat_name. |
So basically you can assign any value to this and in case of showing episodes for the categories, then you could pass in like this: I may be wrong here in understanding what you are doing. |
Yes. That's it. You understand it correctly But then when I use pagination for episodes I must do but when I am doing it for categories I must do But because in both cases I am displaying episodes, but just for different parents I use the same partial. And now in the same partial I must have an if. And given that I have a playlists, that is another collection of episodes, where again the episodes are display it is there the same partial but with different special logic. Wouldn`t it be easier if we build a config property for will_paginate? Something like set_number_first_page: true |
Yes, this is is not the cleanest and prettiest way to do it. It gets the job done 😄 I think this thread(https://www.ruby-forum.com/topic/182815) would also be of interest to you as it revolves around the same problem. Although solutions there are completely different. |
Thanks. Reading the threads now. |
I have an index
/categories
The page
/categories?page=2 generates a link to /categories?page=1
The problem is that /categories?page=1 and /categories is seen by search engines as two different urls but they are actually the same content. So the search engine sees identical content on two pages and I should use a canonical.
Is there a way to say to will_paginate to link the first page as /categories not as /categories?page=1
The text was updated successfully, but these errors were encountered: