Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Invoice < ActiveRecord::Base
- belongs_to :employee
- end
- class Employee < ActiveRecord::Base
- has_many :invoices
- # the select_menu scope takes an employee instance as an argument
- # and adds this employee to the list of 'active' employees
- scope :active, where(active: true)
- scope :select_menu, lambda { |another_employee| active << another_employee }
- end
- /views/invoices/_form.html.erb
- <%= simple_form_for @invoice do |f| %>
- <%= f.association :employee, collection: Employee.select_menu(@invoice.employee).sort_by(&:name), label_method: :first_last, include_blank: "" %>
- ...
- <% end %>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement