This works for me in Rails 3 
<%= form_for ... do |form| %>
<%= form.collection_select(:category_id, Category.all, :id, :category_type) 
%>

I am not super familiar with HAML, but I googled github haml 
collection_select and the code examples that I saw seem consistent with 
what I am offering..

collection_select prototype from 
http://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-collection_select:
collection_select(object, method, collection, value_method, text_method, 
options = {}, html_options = {})

Returns <select> and <option> tags for the collection of existing return 
values of method for object's class. The value returned from calling method 
on the instance object will be selected. If calling method returns nil, no 
selection is made without including :prompt or :include_blank in the 
options hash.

The :value_method and :text_method parameters are methods to be called on 
each member of collection. The return values are used as the value 
attribute and contents of each <option> tag, respectively. They can also be 
any object that responds to call, such as a proc, that will be called for 
each member of the collection to retrieve the value/text.

Rewrite:
= form_for ... do |form| 
 = form.collection_select(nil,  :category_id,  Category.all, :id, :name, 
{:include_blank => true}, {:style => "width:300px"})
    ## I think that you may omit nil as the object, maybe your object here 
is @package??
  = form.collection_select(nil, :sub_category_id, 
@package.category.sub_categories.all, :id, :name, {:include_blank => 
false}, {:style => "width:300px"})

Hope this helps

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/3d821dd2-d91b-499d-a8f1-268dc6558716%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to