Hi, all,

  I setup a drop down box that has data populated by the database.

This is for a simple application where by I am trying to add a new
"Part".
A part has a category and sub category.
 The latter is optional.

When a category has been selected, an ajax query is made to the
database backend to
extract the subcategory options available for the selected category.

This has been implemented and works great for the task of adding a new
"Part" entry (ie. http://localhost:3000/parts/new) .

I did it by refering to the explanation in 
http://shiningthrough.co.uk/blog/show/6.
It was good.

Nevertheless, when I need to edit a given part (ie. 
http://localhost:3000/parts/22/edit),
I keep getting this silly error message below.
"undefined method `map' for "#<Category:0x103231d20>":Category".

This is the full extract of the error messages:


============Extract Begin===============================
 NoMethodError in Parts#edit

Showing app/views/categories/_form.html.erb where line #3 raised:

undefined method `map' for "#<Category:0x1036113c8>":Category

Extracted source (around line #3):

1:     <%= label :category, :id, 'Category' %> <br />
2:     <%= collection_select(
3:             :part,
4:             'category_id',
5:             @categories,
6:             :id,

Trace of template inclusion: app/views/parts/edit.html.erb
============Extract End===============================




Here's what my other files look like:

app/views/parts/new.html.erb
----------------------------------------

1 <h1>Add a new part </h1>
  2
  3 <% form_for(@part, @make, @model) do |f| %>
  4   <%= f.error_messages %>
  5
  6   <p>
  7     <%= f.label :title %><br />
  8     <%= f.text_field :title %>
  9   </p>
 10

11     <span id="category_div">
 12     <%= render :partial => 'categories/form',
 13         :locals => {:category => @categories} %>
 14
 15     <span id="subcategory_div">
 16     </span>
 17
 18   <p>
 19     <%= observe_field :part_category_id,
 20         :url => { :action => :get_subcategories },
 21         :update => :subcategory_div,
 22         :with => "'category=' + value"
 23     %>
 24   </p>

 ...


app/views/parts/new.html.erb
----------------------------------------

  1 <h1>Editing part</h1>
  2
  3 <% form_for(@part) do |f| %>
  4   <%= f.error_messages %>
  5
  6   <p>
  7     <%= f.label :title %><br />
  8     <%= f.text_field :title %>
  9   </p>
 10
 11     <span id="category_div">
 12     <%= render :partial => 'categories/form',
 13         :locals => {:category => @categories} %>
 14
 15     <span id="subcategory_div">
 16     </span>
 17
 18   <p>
 19     <%= observe_field :part_category_id,
 20         :url => { :action => :get_subcategories },
 21         :update => :subcategory_div,
 22         :with => "'category=' + value"
 23          %>
 24   </p>
 25
 26   <p>
 27     <%= f.submit 'Update' %>
 28   </p>
 29 <% end %>
  ...

app/views/categories/_form.html.erb
-------------------------------------------------

  1     <%= label :part, 'category_id', 'Category' %> <br />
  2     <%= collection_select(
  3             :part,
  4             'category_id',
  5             @categories,
  6             :id,
  7             "name",
  8             {:include_blank => true}
  9         )
 10     %>


Any ideas?




What I have referenced:
===================
http://guides.rubyonrails.org/form_helpers.html
http://shiningthrough.co.uk/blog/show/6
http://www.kahfei.com/?p=23


--~--~---------~--~----~------------~-------~--~----~
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 rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to