Hi,
I?m following the Depot tutorial in Agile Web Development with Rails.
I need some help to display products thats in one specific category.
mysql> select * from products where category = "jackets" does what
I
want, but I?m not sure how to make a list and display it in rails?
This code displays every product with some of its fields, but I want
it to only display the products that has the field category set to
"jacket"
<% for product in @products -%>
<div class="catalogentry">
<img src="<%= product.image_url %>"/>
<h3> <%= product.brand %> <%= h(product.title) %>
</h3>
<%= product.description %>
<br>
I would be very grateful it anyone could help me out with some
examples or point me in the right direction.
Best regards,
Martin Stabenfeldt
Add to your controller:
@products=Product.find(:all, conditions =>
"category=''jackets''")
And the same code you have in your view will display just the products you
want.
HTH
Juanjo
----- Original Message -----
From: "Martin Stabenfeldt" <martin@stabenfeldt.net>
To: <rails@lists.rubyonrails.org>
Sent: Monday, March 06, 2006 11:07 AM
Subject: [Rails] Rails MySQL query
Hi,
I?m following the Depot tutorial in Agile Web Development with Rails.
I need some help to display products thats in one specific category.
mysql> select * from products where category = "jackets" does what
I
want, but I?m not sure how to make a list and display it in rails?
This code displays every product with some of its fields, but I want
it to only display the products that has the field category set to
"jacket"
<% for product in @products -%>
<div class="catalogentry">
<img src="<%= product.image_url %>"/>
<h3> <%= product.brand %> <%= h(product.title) %>
</h3>
<%= product.description %>
<br>
I would be very grateful it anyone could help me out with some
examples or point me in the right direction.
Best regards,
Martin Stabenfeldt_______________________________________________
Rails mailing list
Rails@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails
Hi,
I first tried this in store_controller.rb:
# Display the catalog, a list of all salable products.
def index
@products = Product.find(:all, conditions => "category =
''''jackets''")
end
But then I got this error message:
NameError in Store#index
undefined local variable or method `conditions'' for
#<StoreController:
0x23e7e40>
tried to change that back to its original setting, and change
product.rb instead, but this produces a blank page. It doesn''t
display anything.
def self.salable_items
find(:all,
:conditions => "date_available <= now()",
:conditions => "category = ''jackets''"),
:order => "date_available desc")
end
Made store_controller.rb look like it did to start with:
def index
@products = Product.salable_items
end
This didn''t work either.
Please let me know if you can see what I have done wrong or have any
other suggestions! :)
Regards,
Martin
On Mar 6, 2006, at 11:20 AM, Juanjo Baz?n wrote:
> Add to your controller:
>
> @products=Product.find(:all, conditions =>
"category=''jackets''")
>
> And the same code you have in your view will display just the
> products you want.
> HTH
> Juanjo
>
>
>
> ----- Original Message ----- From: "Martin Stabenfeldt"
> <martin@stabenfeldt.net>
> To: <rails@lists.rubyonrails.org>
> Sent: Monday, March 06, 2006 11:07 AM
> Subject: [Rails] Rails MySQL query
>
>
> Hi,
>
> I?m following the Depot tutorial in Agile Web Development with Rails.
> I need some help to display products thats in one specific category.
> mysql> select * from products where category = "jackets" does
what I
> want, but I?m not sure how to make a list and display it in rails?
>
> This code displays every product with some of its fields, but I want
> it to only display the products that has the field category set to
> "jacket"
> <% for product in @products -%>
> <div class="catalogentry">
> <img src="<%= product.image_url %>"/>
> <h3> <%= product.brand %> <%= h(product.title) %>
</h3>
> <%= product.description %>
> <br>
>
> I would be very grateful it anyone could help me out with some
> examples or point me in the right direction.
>
> Best regards,
> Martin Stabenfeldt_______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
> I first tried this in store_controller.rb: > # Display the catalog, a list of all salable products. > def index > @products = Product.find(:all, conditions => "category = >''''jackets''") > endIt should be :conditions (with a colon) instead of conditions.
Thanks! On Mar 6, 2006, at 1:04 PM, Juanjo Baz?n wrote:>> I first tried this in store_controller.rb: >> # Display the catalog, a list of all salable products. >> def index >> @products = Product.find(:all, conditions => "category = >> ''''jackets''") >> end > > It should be :conditions (with a colon) instead of conditions.Now it worked! :) Best regards, Martin Stabenfeldt