On a department’s products page (index.js.rjs), there is a table
showing the products with their id, name, category. The view of this
table is specified by a partial file called _index.html.erb. I’m
going to add in a selection/option drop down menu above the table to
show all the product categories. When the user selects a category
from the drop down menu, Ajax kicks in such that the table (not the
entire page) will be updated with just the products that have category
equal to the selected category (i.e. a filtering operation).
File “_index.html.erb” has,
File “_product.html.erb” has,
<% if :filter_by_category == product.category %>
The questions that I have:
Right now, when I select a category, nothing happens. The server
log shows no activity at all.
Do I need a “no-op” form to enclose my table?
<% end %>
Do I need onChange for the select_tag?
The current HTML codes have this:
Does that mean I have to create a helper/controller for
filter_by_category? If so, what should it contains? All I want is to
refresh the table.
Do I need to specify more options for observe_field, such as
In “_product.html.erb” the “filter_by_category” is not set to the
selected category name after a user selection.
Is there a better way to implement such kind of dynamic filtering?
What about using link_to_remote instead of observe_field? The user
first selects the category, then clicks on the link_to_remote for the
table to refresh. With this approach, I could at least make it to
refresh the table. However, I still don’t know how to capture/specify
the selected value to be used in the partial for filtering purpose.
Any response is highly appreciated.