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?
Thanks!
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 tolink_toinstead of as an argument toreports_path.