Search code examples
ruby-on-railsruby-on-rails-4filterfeedrailstutorial.org

Filtering Posts in Feed - Rails 4


I'm working on a Rails app based on the railstutorial.org book/tutorial. I've added some attributes to my post so that a post has an offered pay and a date (in the future).

I'd like to filter the feed based on user selected filters such as posts where the pay is between x and y, and the date is before xyz, etc. After searching online I considered scopes to accomplish this, but don't fully understand them and didn't find good documentation for them. I need a way to temporarily store the filters the user selects and use them to query the database and return the correct posts.

I've successfully gotten the information from the view to the controller, but am struggling finding a good way to store the filter settings in my application to use between controller actions.

Does anyone have any suggestions on how to attack this issue? I'm not sure what code would be useful, but let me know and I can upload the files. Thanks!


Solution

  • You should be able to save the filters either in the session or in the cookies.

    session is preferred between the two, as it can hold lot more data, compared to cookies, which have a lower limit.

    Refer to session and cookies for more info.