Hi Fred,

Thanks for looking into my problem.

> That's setting yourself up for has_and_belongs_to_many ... (the earlier 
> snippet from
> your models suggests no)

Right, I don’t want that. I want:
An Expense has a Vendor.
A Vendor has many Expenses.

I believe that’s reflected in: app\models\vendor.rb:
    class Vendor < ActiveRecord::Base
      has_many :expenses
    end
and in app\models\ expense.rb:
    class Expense < ActiveRecord::Base
      belongs_to :vendor
    end:

> Assuming Vendor belongs_to :expense then
> f.collection_select :vendor_id, @vendors, :id, :name
> would do the trick

Au contraire:  My concept is that every Expense belongs to some
Vendor.  However,  every Vendor can have many different Expenses
(incurred, as it were, at various times).

But I like your f.collection statement,  though I feel I need to set
@vendors somewhere to:
@vendors = Vendor.find( :all, order=:>”nickname ASC”),
perhaps just before the collection_select statement or in the Vendor’s
controller (but within what method?)

Here’s what I wound up with in app\views\expenses\new.html.erb:
    <%# New version of vendor selection -%>
    <% @vendors = Vendor.find( :all, :order=>"nickname ASC") -%>
    <%= f.collection_select(:vendor, :vendor_id,
@current_vendors, :id, :nickname) %>
    <%# End of New version -%>

That gave me:
    undefined method `merge' for :nickname:Symbol (referencing the
collection_select line)

But I think “nickname” is defined for Vendor, to wit:
mysql> show columns in vendors;
+------------+--------------+------+-----+---------+----------------+
| Field      | Type         | Null | Key | Default | Extra          |
+------------+--------------+------+-----+---------+----------------+
| id         | int(11)      | NO   | PRI | NULL    | auto_increment |
| nickname   | varchar(255) | YES  |     | NULL    |                |
| qbname     | varchar(255) | YES  |     | NULL    |                |
| created_at | datetime     | YES  |     | NULL    |                |
| updated_at | datetime     | YES  |     | NULL    |                |
+------------+--------------+------+-----+---------+----------------+
5 rows in set (0.02 sec)

Any ideas?

Thanks in Advance,
Richard

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to