I have googled/stackoverflowed for hours but did not find any thing that matches to my requirements. I am new in rails and I am working on a bug tracking system in rails 4.2.4. Here I have a class named Bug. On the creation of bugs, I have two drop down menus that will be populated with the array values from model. My model looks like this:
class Bug < ActiveRecord::Base
belongs_to :creator, :class_name => "User", :foreign_key => "creator_id"
belongs_to :developer, :class_name => "User", :foreign_key => "developer_id"
TYPE = ['Feature', 'Bug']
FEATURE_STATUS = ['New', 'Started', 'Completed']
BUG_STATUS = ['New', 'Started', 'Resolved']
validates :title, :presence => true, :uniqueness => true
validates :status, :type, :presence => true
has_attached_file :screen_shot
validates_attachment_content_type :image, :content_type => ["image/jpg", "image/jpeg", "image/png", "image/gif"]
end
There is some code from _form.html.erb file which will display drop down options:
...
...
...
<div class="form-group">
<%#= f.label :bug_type, class: "col-sm-2 control-label" %>
<%= f.label :bug_type, t('.bug_type') + ":" %>
<%= f.select :bug_type,
Bug::TYPE,
:prompt => "Select bug type:"
%>
</div>
<div class="form-group">
<%#= f.label :status, class: "col-sm-2 control-label" %>
<%= f.label :status, t('.status') + ":" %>
<%= f.select :status,
Bug::FEATURE_STATUS,
:prompt => "Select status:"
%>
</div>
...
...
...
At the current time, my code is displaying values of array Bug::TYPE in first drop down, and values from Bug::FEATURE_STATUS in second drop down. My question is how to populate second drop down with array values depending upon value of first drop down? That is, if the user selects a value 'Feature' from the first drop down, second drop down should display values of FEATURE_STATUS array. And if the user selects a value 'Bug' from the first drop down, then the second drop down should display values of array FEATURE_BUG.
I am new to stack over flow, and this is my second question I asked here. Any help will be highly appreciated. Thanks in advance.