Guest User

Untitled

a guest
May 27th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. class Company < ActiveRecord::Base
  2. has_many :projects
  3. has_many :users
  4.  
  5. #used for creation of new companies with related objects
  6. attr_accessor :new_user
  7. attr_accessor :new_project
  8. attr_accessor :new_message
  9.  
  10. def initialize(*args)
  11. super
  12. self.new_user = self.users.build
  13. self.new_project = self.projects.build
  14. self.new_message = self.new_project.messages.build
  15. self.new_message.user = self.new_user
  16. end
  17. end
  18.  
  19. companies_controller.rb
  20.  
  21. def new
  22. @company = Company.new
  23. end
  24.  
  25. in the view, new.html.erb:
  26. you can do whatever you want with them:
  27.  
  28. <% user = @company.new_user %>
  29. <% project = @company.new_project %>
  30. <% message = @company.new_message %>
Add Comment
Please, Sign In to add comment