Hi Hassan,
Thanks for your continued consideration of my problem. I hope some of
the following is helpful, though it seems like way to much
information.
? I'm looking at (unframed)
<http://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelp...>
with this 'sample usage':
collection_select(:post, :author_id, Author.all, :id,
:name_with_initial, {:prompt => true})
Here’s the section of of the doc I looked at:
ActionView::Helpers::FormOptionsHelper,
which seems to match the portion you cited.
Are you sure you got the *exact same* error using :nickname ?
Since this section referenced a method that returned a string, I took
a short-cut to simply name an object whose value was a string. But in
case that’s the cause of the problem, I changed my app to closely
follow the example in the doc.
If so, what's the code that creates @vendors ?
Good question: I DON’T KNOW! I see a several methods in app
\controllers\vendors_controller.rb the populate @vendors with
Vendor.all.
Maybe the absence of an assignment to @vendors is what’s wrong, but I
don’t know what to do about it/
Carrying on in case the changes I made are useful, I note that this
section shows the command format as follows:
collection_select(object, method, collection, value_method,
text_method, options = {}, html_options = {})
It shows the object structure to be used with this method:
class Post < ActiveRecord::Base
belongs_to :author
end
class Author < ActiveRecord::Base
has_many :posts
def name_with_initial
"#{first_name.first}. #{last_name}"
end
end
I’ve got: app\models\expense.rb:
class Expense < ActiveRecord::Base
belongs_to :vendor
end
and app\models\vendor.rb:
class Vendor < ActiveRecord::Base
has_many :expenses
def name
#{nickname}
end
I’ve got a *revised* app\views\expenses\new.html.erb, lines 8-12 in
order to follow the example more exactly:
<p>
<%= f.label :vendor %><br />
<%= f.collection_select(:vendor, :vendor_id,
@vendors, :id, :name) -%>
<%= link_to 'New
Vendor', :controller=>'vendors', :action=>'new' %>
</p>
When I run the app and click on the New Expense link, I get a
*revised* symptom, which is the error page below starting with
**NoMethodError in Expenses#new** in 24-point font.
I can post all the app’s code or any partion thereof in a zip file if
that would be helpful to you.
Thank you for helping me to get this functionality going.
Best wishes,
Richard
NoMethodError in Expenses#new
Showing app/views/expenses/new.html.erb where line #10 raised:
undefined method `merge' for :name:Symbol
Extracted source (around line #10):
7:
8: <p>
9: <%= f.label :vendor %><br />
10: <%= f.collection_select(:vendor, :vendor_id,
@vendors, :id, :name) -%>
11: <%= link_to 'New
Vendor', :controller=>'vendors', :action=>'new' %>
12: </p>
13: <p>
RAILS_ROOT: K:/_Projects/Ruby/_Rails_Apps/_EIMS/RTS
Application Trace | Framework Trace | Full Trace
K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/
actionpack-2.3.5/lib/action_view/helpers/form_helper.rb:1025:in
`objectify_options'
K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/
actionpack-2.3.5/lib/action_view/helpers/form_options_helper.rb:588:in
`collection_select'
K:/_Projects/Ruby/_Rails_Apps/_EIMS/RTS/app/views/expenses/
new.html.erb:10:in `_run_erb_app47views47expenses47new46html46erb'
K:/_Projects/Ruby/_Rails_Apps/_EIMS/RTS/app/views/expenses/
new.html.erb:5:in `_run_erb_app47views47expenses47new46html46erb'
K:/_Projects/Ruby/_Rails_Apps/_EIMS/RTS/app/controllers/
expenses_controller.rb:30:in `new'
Request
Parameters:
None
Show session dump
Response
Headers:
{"Content-Type"=>"text/html",
"Cache-Control"=>"no-cache"}