Search code examples
ruby-on-railsruby-on-rails-2

How to save result of search in DB to show it many times?


Let's imagine I have Articles in my system. I can show list of Articles based on search query which includes date ranges, category or few categories, tag or few tags, author or few authors. So I need to show filtered list of Articles to user and give him a possibility to copy link to this list and share. But in my case the link have to be unique hash, like this: mysite.com/articles/hsdjfh7yasdfhkfuh7sdfhidsfhkd

Do I have to store it in DB to provide this functionality? If yes - how to do that?


Solution

  • You can use an encryption/decryption system to generate the hash: you encrypt the search query parameters to create the hash, and you decrypt the hash when you receive it from mysite.com/articles/hsdjfh7yasdfhkfuh7sdfhidsfhkd to retrieve the search params and regenerate the list of articles.

    Look at the crypt gem for some encryption/decryption algorithms.