base on @Georg Ledermann answer I take this small snapshot of the code to redirect to path editing if the user hits back and then creates hits.
#application_controller.rb private def redirect_to_on_back_and_create(object) if session[:last_stale].present? and session[:last_stale_id].present? and session[:last_stale].to_i == params[:stale_form_check].to_i redirect_to edit_polymorphic_path(object.class.find(session[:last_stale_id].to_i)), alert: "Este #{object.model_name.human} ya ha sido creado, puedes editarlo a continuación" else if object.save session[:last_stale] = params[:stale_form_check].to_i session[:last_stale_id] = object.id redirect_to object, notice: "#{object.model_name.human} Creado con éxito" else render :new end end end
And finally add the @stale_form_check parameter to your form
<%= hidden_field_tag :stale_form_check, @stale_form_check %>
You can always abstract this method where you need it, but in this way you could avoid a lot of repetition in your project if you need this behavior in many parts
I hope this helps the next one, I used redirect_on_back gem to use it, but this time it didn’t work for me, the _usec parameter that uses this gemstone was always reset, so it can not be compared every time it was necessary
Alexis
source share