C
C
Ciscoridze2014-09-23 13:09:18
Ruby on Rails
Ciscoridze, 2014-09-23 13:09:18

How to make an unusual association in simple_form (rails)?

Good afternoon.
There is a form for creating a trouble ticket:

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

How can I make it so that when selecting a department ( <%= f.association :department...) the users from the second dropdown menu are only from that department, not User.all. What parameters to give the rails? By what means is this resolved?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
F
FanKiLL, 2014-09-23
@FanKiLL

Check out the Dynamic Select Menus screencast from railscasts.com , which does exactly what you need.
There is a newer version of the screencast, but a subscription is required. I have a new version, only xs where to upload it and whether it is necessary to download it on rutracker.

V
vsuhachev, 2014-09-23
@vsuhachev

This can only be done with javascript, one of the options is to hang a handler on the first select on the 'change' event, which makes an AJAX request to the server, receives the necessary users and fills in the second select. Google ajax master-detail select boxes

D
Dron Krzh, 2014-09-23
@ walkman7

This is done via Ajax, when the user has selected a department, users from the selected department are loaded.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question