I’m using a pulldown box that contains a list of the categories. I’ve
tried some simple variations, but can’t seem to get it. It has to be
something silly. I included the form code at the bottom.
Here’s the controller:
def listItemsInCategory @items = Item.find_all(params[:item])
end
I could be wrong here, but I don’t think that find_all wants a hash. If
you
are just trying to get all of the records use Item.find_all. If you
need to
use conditions you can do Item.find(:all, :conditions =>
“place-condition-here”) or even something like
Item.find_all_by_category_id(
params[:category_id] )
I’m using a pulldown box that contains a list of the categories. I’ve
tried some simple variations, but can’t seem to get it. It has to be
something silly. I included the form code at the bottom.
Here’s the controller:
def listItemsInCategory @items = Item.find_all(params[:item])
end
categoryPulldown
<% @items.each do |category| %>
>
<%= category.name %>
<% end %>
<%= submit_tag "find"%>
Thoughts???
Something else must be going on. The only code in there that queries
the database is in the controller’s find_all. Nothing in that view
should require a databse call, therefore you should not get a databse
error. Double check your stack trace to find exactly which line of your
code is making this happen.
I could be wrong here, but I don’t think that find_all wants a hash. If
you
are just trying to get all of the records use Item.find_all. If you
need to
use conditions you can do Item.find(:all, :conditions =>
“place-condition-here”) or even something like
Item.find_all_by_category_id(
params[:category_id] )
Rob
Hmmm…
The conditions are the problem. I can easily pull ALL of the records.
What I need to do is pull the records based on the selected field of the
dropdown menu in my form.
To put it in context, your “place-conditions-here” is the part I’m
trying to figre out. How do I pull those conditions out of my passed
form data?
I think that “Item.find_all_by_category_id(params[:category_id])”
translates to:
SELECT * FROM items WHERE category_id LIKE ‘category_id11’
It doesn’t generate an error, but if pulls no rows either.