Dynamic loading of options in select menu for a form whilst using formtastic
I have a formtastic form. And the problem is simple. I have 2 select menus. Based on the option selected in the 1st select menu, the 2nd select menu should be populated. I have this in my form code.
<% semantic_form_for @issue, :ht开发者_StackOverflow社区ml => { :multipart => true } do |form| %>
<% form.inputs do %>
<%= form.input :department, :remote => true, :input_html => { :onchange => remote_function(:url => { :action => :get_issue_types }, :method => :get, :with => "'dep_id='+this.options[this.selectedIndex].value")} %>
<%= form.input :issue_type %>
<% form.buttons do %>
<%= form.commit_button "Submit" %>
<% end %>
<% end %>
So based on the value selected for department, the issue type menu should be correspondingly populated. This is my remote action in my controller:
def get_issue_types
@issue_types = (params[:dep_id].blank?) ? [] : Department.find(params[:dep_id]).issue_types.uniq
end
And this is the error I get:
ActiveRecord::RecordNotFound (Couldn't find Issue with ID=get_issue_types)
How do I make this work? Thanks!
精彩评论