rails multiple form selects

2019-06-10 10:48发布

I have a rails form with 2 selects where one of them depends on the the selected value of the other. So if I have 3 users and 5 items per user, once a user is selected I want the items selection to contain only the items specific to that user. Sounds pretty straightforward but I'm having a very difficult time getting this working. Here's the code where instead of users and items I have vendor_identifier and app_identifier (so a vendor may have many apps for example). Thanks very much in advance for your help!!

<p>
    <%= f.label :vendor_identifier %><br />
    <%= f.select :vendor_identifier, User.find(:all, :order => "last_name, first_name").collect {|u| [(u.first_name + " " + u.last_name), u.userid]} %>
  </p>
  <p>
    <%= f.label :app_identifier %><br />

    <%= f.select :app_identifier, App.find(:all, :conditions => {:vendor_identifier => :userid } , :order => "name") %>
  </p> 
  <p>

1条回答
ゆ 、 Hurt°
2楼-- · 2019-06-10 11:23

I've written a guide on updating a select box based on another which you may find helpful: http://ryanbigg.com/2008/05/updating-a-select-box-based-on-another

查看更多
登录 后发表回答