我有困难添加查询字符串参数到link_to UrlHelper。例如,我有一个Index视图,它有用于排序、过滤和分页(通过will_paginate)的UI元素。will_paginate插件正确地管理查询字符串参数的页内持久性。
是否有一种自动机制来添加查询字符串参数给指定路由,还是我需要手动这样做?关于这个看似简单的结构的大量研究让我毫无头绪。
Edit
以下是挑战:
If I have two querystring parameters, bucket & sorting, how do set a specific value to one of these in a link_to, while preserving the current value of the other? For example: <%= link_to "0", profiles_path(:bucket => '0', :sorting=>?? ) %> If I have multiple querystring parameters, bucket & sorting & page_size, and I want to set the value to one of these, is there a way to 'automatically' include the names and values of the remaining parameters? For example: <%= link_to "0", profiles_path(:bucket => '0', [include sorting and page_size name/values here] ) %> The will_paginate plugin manages its page variable and other querystring variables automatically. There doesn't seem to be an automatic UI element for managing page size. While I've seen code to create a select list of page sizes, I would rather have A elements for this (like SO). Part of this challenge is related to #2, part is related to hiding/showing this UI element based on the existence/non-existence of records. Said another way, I only want to include page-size links if there are records to page. Moreover, I prefer to automatically include the other QS variables (i.e. page, bucket, sorting), rather than having to include them by name in the link_to.