title: Rails: controller#show logic for a link_to root_path or :back
body: <p>How do I set up a Controller#show layouts "OK" button so that it will <code>link_to root_path</code> if the user is coming through the <code>new</code> > <code>create</code> actions </p>
  
  <p><em>but</em></p>
  
  <p>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)? </p>
  
  <p>I'm using <code>store_location</code> and <code>redirect_back_or(default)</code> helper methods to handle <code>login_required</code> for certain controllers (including this controller). Can this be adopted to also work with my issue above? Or is there a better way? </p>
  
  <p>In a nutshell, I think the button wants to <code>link_to "OK", :back</code> unless the previous action was the create (or sign_in) action.</p>
  
  <p>I don't think we need to involve the <code>session</code> 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.</p>