سؤال

How do I set up a Controller#show layouts "OK" button so that it will link_to root_path if the user is coming through the new > create actions

but

if user is viewing a list of already existing resources (effectively an index), then clicks on one to see the Controller#show (details), then the "OK" button will now take them back to the previous page (index)?

I'm using store_location and redirect_back_or(default) helper methods to handle login_required for certain controllers (including this controller). Can this be adopted to also work with my issue above? Or is there a better way?

In a nutshell, I think the button wants to link_to "OK", :back unless the previous action was the create (or sign_in) action.

I don't think we need to involve the session because the link doesn't need to persist. It's just one thing if it's coming from an index and another if it's coming from create or (sign_in)...just not sure how to do it.

لا يوجد حل صحيح

نصائح أخرى

So, in new > create actions the user is redirected to Controller#Show. You can just pass a parameter along with it. For Eg you can modify your redirect_to to something like the following:

<%= redirect_to show_path(:param1 => "true") %>

Then in your #Show page, you can check

<% if !params[:param1].nil? and params[:param1] == true %>
     <%= link_to "OK", root_path %>
<% else %>
     <%= link_to "OK", :back %>
<% end %>
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top