In my rails app, I need to filter a database and print the results.
Initially, when you load the web page, all the results are listed in
all their non filtered glory. So what I've done is added a button and
a drop down list. The list holds the types by which you'd like to
filter, and the button starts the filter (in theory).
The problem is... I'm not sure how to do the filter. Queries sound
like they would be the best bet. I could call a query based on the
filter type and print the results. But where would I query? In a
controller? A query would need to be done every time the filter button
was pressed. Is it possible to ask for a query in the rhtml code?
Since I honestly didn't know, I tried another approach. I defined a
ruby method in the rhtml:
<!-- Ruby organize method for filter -->
<% def organize ( f_type ) %>
<% @clients.each do |client| %>
<-- a bunch of code here -->
<% end %>
And after I was on the verge of success, I got an error:
undefined local variable or method `_erbout' for #<#<Class:0x438701c>:
I did some research and what I gathered is that I'm a horrible person
for trying to define a ruby method in the rhtml. I thought about
defining the method in a controller, but the method includes html code
in order to print out the filtered list. So that wouldn't work. Now
I'm stumped. Should I use queries? If so, how would I? Or am I wrong
about _erbout and take the method approach?
I have one other question. Lets say I want to do something based on
the value picked in a drop down list (like... filter!). Is there a
variable that stores the picked drop down list value so that I can use
it in a conditional?
Thanks for your help,