Hi I have two models in Rails: invoices and products.
Each invoice has one or many products. And each product belongs to one or many invoices.
On the invoices view, I would like to select the product name in a drop down list. The list needs to contain all the products available. If I insert another product in the product view, this new product needs to show on the drop down list on the invoices view. The name of the product needs to show in the drop down list on the invoice's view.
How do you program this in Rails 2.0? I had it working on the previous version of Rails but it broke when I migrated to Rails 2.0.
What is the code for the invoice controller, for the invoice views (edit, create and change)?
Newbie on Rails
you want to use the select tag
in a basic usasge
-form_for @product
=f.select :category, Category.all(:condtions => {..get your name here..})
=f.select :category, Category::CATEGORIES #=> I like this solution more
=f.select :category, Category::CATEGORIES, :include_blank => true #=> if you want a blank field
# for my preferred method, a static array of options in Category class
class Category< ActiveRecord::Base
CATEGORIES = %w(new used)
end
or if you want to use an options value for the categories, eg used references 1 in the database, then checkout
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.