Two Quick Questions

These are 2 basic questions that I’m stuck with:

  1. Going ‘:back’ to the referring page
    I’d like to create a link that allows the user to go to the referring
    page. I saw this solution:
    <%= link_to ‘Back’, @request.env[“HTTP_REFERER”] %>
    But, naturally, this creates a link that is a fresh call to the previous
    page. This loses the request parameters loses the effect of the query
    that created the previous page… (in fact, results in an exception) The
    other way seems to be javascript:
    Go back
    Is this the only practical way?

  2. How do I formulate a transaction across two tables?
    I want to delete a “request” if I can successfully save the “data” - the
    examples in AWDWR (i think) only talk about transactions on 1 table and
    specifically say that it’s not supported across databases… but have
    been unable to determine anything about two tables in the same
    database…

Thanks
Mohit.

In regards to question 1:

I have run into this problem at times also. You could possibly
consider creating a “request cache” if going back is that important to
you. Something along these lines, although this code may not be
complete or working. It’s a concept demonstration.

session[:cache] ||= []
session[:cache] << params

def back
if session[:cache] && last_params = session[:cache].pop
redirect_to last_params
end
end

In regards to question 2, I assume you have some sort of “request”
modelled in the database:

if data.save
myrequest.destroy
end

Is this what you are referring to?