Rails routing: still a bit confused on how to pass a query param through different requests

On a search page I submit a query to the index action via a form:

= form_tag reports_path, method: 'get' do
  = text_field_tag :query, params[:query]

I successfully pass it from reports#index view into #show view with:

= link_to params[:query] ? query_report_path(report.id, params[:query]) : report do

which is possible because of this route:

  resources :reports do
    get ':query', to: 'reports#show', on: :member, as: :query

but I'm trying to get same query back to #index action from a link in the reports#show view with:

= link_to 'Back', reports_path, query: @query

but it's failing: :query = nil.

also tried:

= link_to 'Back', reports_path(query: @query, class: 'btn btn-small')

which doesnt' work at all...

routing syntax has me tripped up...again! What's the correct syntax? Is there a better way to do this? Why wouldn't this trigger the same get reports#index with :query param that the initial form_tag is triggering?



I think your second try is close but your parentheses are wrong. Try passing the HTML options hash class: 'btn btn-small' as the third argument to link_to instead of as an argument to reports_path.

Need Your Help

thread-safety question

c++ thread-safety

A simple situation here,

Should I use Java applets or Flash to make webpage-embeddable physics simulations?

java flash simulation physics

I want to start working on some simple physics simulations that I can embed onto my website. I have a lot of experience with web programming with languages like PHP and javascript, a fair amount of

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.