2014-09-23 80 views
0

我有這樣的形式:Simple_form和關聯

<%= simple_form_for @request, html: {class: 'form-horizontal' } do |f| %> 
    <%= f.input :initiator, label: 'initiator' %> 
    <%= f.association :department, collection: Department.all, value_method: :id, label: 'Назначить на отдел' %> 
    <%= f.association :user, collection: User.all, label_method: :email, label: 'Ответственный' %> 
    <%= f.input :comment, label: 'comment' %> 
    <%= f.input :sla, label: 'SLA' %> 
    <%= f.button :submit, label: 'Создать', class: "btn btn-primary" %> 
<% end %> 

我怎樣才能讓協會: 如果讓我選擇「部門1」:系的選擇:用戶只會用戶誰屬於這個部。 (當你打開下拉列表只有部門1的人,而不是Users.all)我必須通過什麼參數導軌?

+1

我希望這應該可以幫助你, http://stackoverflow.com/questions/6863990/ruby-on-rails-drop-down-box-on-change-event – Sontya 2014-09-23 11:10:09

+1

這也應該有助於http://railscasts.com/episodes/ 88-動態選擇菜單 – kobaltz 2014-09-23 12:48:25

+1

或者如果您有訂閱http:// rails casts.com/episodes/88-dynamic-select-menus-revised – kobaltz 2014-09-23 12:49:02

回答