2

The following form is being used to generate results.

<%= form_tag risultati_fatturati_interventos_path do %>   <div class='row'>
    <div class='small-6 medium-6 large-6 columns'>
      Dal: <%= date_select :intervento, :dal, { order: [:day, :month, :year], default: Date.today-31, start_year: Time.now.year-1, end_year: Time.now.year, datetime_separator: "&nbsp;" }, {class: "small-3 medium-3 large-3 columns"}  %>
    </div>
    <div class='small-6 medium-6 large-6 columns'>
      Al: <%= date_select :intervento, :al, { order: [:day, :month, :year], default: Date.today-30, start_year: Time.now.year-1, end_year: Time.now.year, datetime_separator: "&nbsp;" }, {class: "small-3 medium-3 large-3 columns"}  %>
    </div>   </div>   <div class='row'>
    <div class='small-6 medium-6 large-6 columns'>
      <%= collection_select(:intervento, :invoicestate_id,  Invoicestate.all, :id, :nome, prompt: "tutti") %>
    </div>
    <div class='small-6 medium-6 large-6 columns'>
      <br /><br />
      <%= submit_tag "Invia" %>
    </div>   </div> <% end %>

The results page allow users to individually edit each record. Upon that action, the controller states redirect_to :back so that the UI leaves the user in a known state.

However the results page is dealing with a query with no parameters. My understanding is submit button does not populate the URL with the parameters, while link_to does.

Various forms of <%= link_to "blurb", params.merge(...) %> are not being digested by rails. How can the results page be generated with parameters in order to allow :back to return proper results?

Jerome
  • 5,583
  • 3
  • 33
  • 76

1 Answers1

0

my understanding from your question above is you want to get to previous page after user do the edit

you can use request.referrer to save the url

  def edit
    # your command ....
    # here you save the session url
    session[:return_to] = request.referrer  
  end

  def update
    # your save command etc
    # here you check if there is value from previous session 
    # then it will go to that url
    if session[:return_to]
      redirect_to session.delete(:return_to)
    else
      redirect_to other_path / root_path
    end
  end
widjajayd
  • 6,090
  • 4
  • 30
  • 41