</span>
<% other_formats_links do |f| %>
- <%= f.link_to 'Atom', :url => params.merge(:from => nil, :key => User.current.rss_key) %>
+ <%= f.link_to_with_query_parameters 'Atom', 'from' => nil, :key => User.current.rss_key %>
<% end %>
<% content_for :header_tags do %>
</table>
<% other_formats_links do |f| %>
- <%= f.link_to 'PDF', :url => params.merge(@gantt.params) %>
- <%= f.link_to('PNG', :url => params.merge(@gantt.params)) if @gantt.respond_to?('to_image') %>
+ <%= f.link_to_with_query_parameters 'PDF', @gantt.params %>
+ <%= f.link_to_with_query_parameters('PNG', @gantt.params) if @gantt.respond_to?('to_image') %>
<% end %>
<% end # query.valid? %>
<% end %>
<% other_formats_links do |f| %>
- <%= f.link_to 'Atom', :url => params.merge(:key => User.current.rss_key) %>
- <%= f.link_to 'CSV', :url => params, :onclick => "showModal('csv-export-options', '350px'); return false;" %>
- <%= f.link_to 'PDF', :url => params %>
+ <%= f.link_to_with_query_parameters 'Atom', :key => User.current.rss_key %>
+ <%= f.link_to_with_query_parameters 'CSV', {}, :onclick => "showModal('csv-export-options', '350px'); return false;" %>
+ <%= f.link_to_with_query_parameters 'PDF' %>
<% end %>
<div id="csv-export-options" style="display:none;">
<% end -%>
<% other_formats_links do |f| %>
- <%= f.link_to 'Diff', :url => params, :caption => 'Unified diff' %>
+ <%= f.link_to_with_query_parameters 'Diff', {}, :caption => 'Unified diff' %>
<% end %>
<% html_title(with_leading_slash(@path), 'Diff') -%>
<span class="pagination"><%= pagination_links_full @entry_pages, @entry_count %></span>
<% other_formats_links do |f| %>
- <%= f.link_to 'Atom', :url => params.merge({:issue_id => @issue, :key => User.current.rss_key}) %>
- <%= f.link_to 'CSV', :url => params, :onclick => "showModal('csv-export-options', '330px'); return false;" %>
+ <%= f.link_to_with_query_parameters 'Atom', :key => User.current.rss_key %>
+ <%= f.link_to_with_query_parameters 'CSV', {}, :onclick => "showModal('csv-export-options', '330px'); return false;" %>
<% end %>
<div id="csv-export-options" style="display:none;">
html_options = { :class => name.to_s.downcase, :rel => 'nofollow' }.merge(options)
@view.content_tag('span', @view.link_to(caption, url, html_options))
end
+
+ # Preserves query parameters
+ def link_to_with_query_parameters(name, url={}, options={})
+ params = @view.request.query_parameters.except(:page, :format).except(*url.keys)
+ url = {:params => params, :page => nil, :format => name.to_s.downcase}.merge(url)
+
+ caption = options.delete(:caption) || name
+ html_options = { :class => name.to_s.downcase, :rel => 'nofollow' }.merge(options)
+ @view.content_tag('span', @view.link_to(caption, url, html_options))
+ end
end
end
end
get '/issues', :project_id => 'ecookbook'
%w(Atom PDF CSV).each do |format|
- assert_select 'a[rel=nofollow][href=?]', "/projects/ecookbook/issues.#{format.downcase}", :text => format
+ assert_select 'a[rel=nofollow][href=?]', "/issues.#{format.downcase}?project_id=ecookbook", :text => format
end
end