Customize page(s) based on a referring search query

Hi

i want to customize a page based on a referring search query and i want
to store the keyword(s) of the referring search query string in my
app-database.

Someone links for some direction how this works in RoR.

remco