Forum: Ruby on Rails checkboxes for filtered search

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
26bf61c1b16036ce19794f100f5f111a?d=identicon&s=25 Robert Zolkos (Guest)
on 2006-04-23 12:04
(Received via mailing list)
I have a page that renders a series of about 20 checkboxes on the
left hand side with content on the right.  These checkboxes are
created from a DB and that part is all working well.

What I want to do is have a user click on a checkbox [genres] and
have the content on the right be filtered based on the checkbox
ticked.  If a user clicks on more than one checkbox than only those
stories are shown.

So for example the tables are like this :

*Stories*
id
title
genre_id

------------------

*Genre*
id
description

-------------------

*genre_stories*
stories_id
genre_id


How do I achieve this?  I also want the checkboxes checked after the
page is refreshed to show the user the current filter applied.


Thanks,

Rob
D0cd6b10e01bacb976b3b815a9c660bc?d=identicon&s=25 Alex Wayne (Guest)
on 2006-04-23 20:37
Robert Zolkos wrote:
> I have a page that renders a series of about 20 checkboxes on the
> left hand side with content on the right.  These checkboxes are
> created from a DB and that part is all working well.
>
> What I want to do is have a user click on a checkbox [genres] and
> have the content on the right be filtered based on the checkbox
> ticked.  If a user clicks on more than one checkbox than only those
> stories are shown.
>
> How do I achieve this?  I also want the checkboxes checked after the
> page is refreshed to show the user the current filter applied.
>
>
> Thanks,
>
> Rob

You're gonna want "form_remote_tag", the idea is that you have an
onclick event for the checkbox that uses javascript to submit the form
data via AJAX.  The AJAX request then updates the right hand side of the
page.

As for keeping the checkboxes checked, from the action that handles the
AJAX request, set the session with something like "session[:search] =
params[:checkboxes]"
This topic is locked and can not be replied to.