Rails Nested Model filter
I'm stucked in Nested models. I have some nested habtm models. The problem is how do i filter habtm nested model results in views.
for exa开发者_如何学编程mple:
#Company.rb
has_many :company_categories
has_many :categories, :through => :company_categories, :order => 'name'
#companies/_form.html.erb (in edit mode)
...
<%= select_tag :filter_by_category, options_for_select(...) %>
...
<%= f.fields_for :company_categories do |builder %>
render 'category_fields', :f => builder
<% end %>
i want to filter results with filter_by_category parameter/
sorry for my ancient english.
You could use javascript to change the options as soon as the filter_by_category field changes. You can easily setup a small jQuery Ajax script that asks the server for the options depending on the value selected.
You could read more about jQuery and it's Ajax stuff here http://api.jquery.com/jQuery.ajax/
精彩评论