Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7657233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:58:32+00:00 2026-05-31T12:58:32+00:00

I search for a working solution for a rather simple problem, but could not

  • 0

I search for a working solution for a rather simple problem, but could not find a good explanation.

What I currently have (working) is an index view which contains:

  • a form to enter a new element and
  • a paginated list of existing elements (using will_paginate).

For the list I am interested in only part of the data, thus I am trying to add a form with filter options and I would like to store the forms content in a cookie (which should be replaced with an per user object stored in the database, but i do not have users yet). What I cannot figure out is how to get the values from the form stored in a cookie (and vice versa) and how to use it together with will_paginated.

What I currently tried to do as a first step is to create an @filter object in my controller and adding the filter form for this object, setting the form options to use the index controller again. This leads to selected filter parameters passed in the params hash to the index controller (visible in the url). But this solution has some drawbacks. first the filters are gone as soon as I change the view (e.g. by creating a new element) and second the @filter object should be the cookie instead.

Here is the code I have so far:

View-partial for filter:

<%= form_for(@filter, :url => {:action => "index"}, :html => {:method => :get}) do |f| %>
  <div class="field">
    <%= f.label :german %><br />
    <%= f.check_box :german %>
  </div>
  <div class="actions">
    <%= f.submit "Filter" %>
  </div>
<% end %>

Controller:

def index
  @word = Word.new
  @filter = Word.new(params[:word])
  @words = Word.paginate(:page => params[:page]).order('word')
  # ....

Can anybody help me? How is such a functionality (filtering results) done in other applications?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T12:58:33+00:00Added an answer on May 31, 2026 at 12:58 pm

    So the answer to the question is, use a where clause to include only the matching records in your result.

    @words = Word
      .where("german = ?", params[:word][:german] != 0")
      .order('word')
      .paginate(:page => params[:page])
    

    This is a new Rails syntax called Active Relation (AREL for short), which should generally replace the older find and find_by methods. It has several benefits that can improve performance, notably that the SQL it executes (which you can see in your logs) only occurs when it is referenced, not when it is declared. This give you neat ways of defining partial relations (even as named scopes) that you can build up to create simpler statements that combine together.

    The order of the various clauses doesn’t matter — AREL will generate the same SQL, but generally I like to follow the order of the underlying SQL,

    • where
    • joins
    • group
    • order
    • limit
    • offset

    (limit and offset are handled in your case by the pagination tool).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone have the same problem or a working solution? I get always this
I have a working solution, but I was wondering if there was a better
I've search for awhile here and can't find a working solution. I am running
Somehow Visual Studio search has stopped working for me. Anytime I search Entire Solution
I am altering the question now! I have the search working using the following:
I'm trying to get a simple search form working in my RoR site. I've
I'm working on a simple search engine for a newspaper application. When the user
The Rabin-Karp search algorithm is working fine but can anyone help to guide me
I am new to flash, so the solution to this problem may be simple.
I am currently working on a live search and I need to be able

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.