Reputation: 1639
I have a users index action that directs a person to different pages depending on the params. Currently when a user passes in search params and I render the custom view template, when a person clicks on a user it goes to their user edit page. I want the back button on the browser to go back to the custom view if thats where the user came from. However, it keeps going back to the users index regardless.
What should I be doing to make the browser back button go back to the last page a user came from?
My controller code is:
def index
@criteria = params[:criteria]
respond_to do |format|
format.js {
unless @criteria.blank? || @criteria.length < 3
@results = fire(@criteria)
render :template =>'admin/users/search_user', :object => @results, :locals => { :autocomplete => true, :criteria => @criteria }
else
@users = User.paginate :page => params[:page], :order => "users.created_at desc"
render :template =>'admin/users/users', :object => @users, :locals => { :autocomplete => true, :criteria => @criteria }
end
}
format.html {
@users = User.paginate :page => params[:page], :order => "users.created_at desc"
}
end
end
This is my understanding of the flow:
Thanks!
Upvotes: 2
Views: 6031
Reputation: 9747
Try <%= link_to 'Back', 'javascript:history.go(-1);' %>
. It will give you exactly same functionality as browser's back button.
Upvotes: 4
Reputation: 1318
What you're describing is basically friendly forwarding. You can't override the browser's default behaviour in that case (unless you want to go down a deep rabbit hole of JavaScript), but you could achieve something user friendly by following a similar pattern to this:
http://ruby.railstutorial.org/chapters/updating-showing-and-deleting-users#sec-friendly_forwarding
Hope that helps, anyway.
Upvotes: 0
Reputation: 103
Not sure, if I understand you correctly, but this could solve your problem, maybe
<%= link_to "Back", :back %>
Upvotes: 1