Advertisement
Guest User

Untitled

a guest
Apr 16th, 2014
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. class Invoice < ActiveRecord::Base
  2. belongs_to :employee
  3. end
  4.  
  5. class Employee < ActiveRecord::Base
  6. has_many :invoices
  7.  
  8. # the select_menu scope takes an employee instance as an argument
  9. # and adds this employee to the list of 'active' employees
  10. scope :active, where(active: true)
  11. scope :select_menu, lambda { |another_employee| active << another_employee }
  12. end
  13.  
  14. /views/invoices/_form.html.erb
  15.  
  16. <%= simple_form_for @invoice do |f| %>
  17. <%= f.association :employee, collection: Employee.select_menu(@invoice.employee).sort_by(&:name), label_method: :first_last, include_blank: "" %>
  18. ...
  19. <% end %>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement