Guest User

Untitled

a guest
Jun 22nd, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. ## my model: client.rb
  2.  
  3. class Client < ActiveRecord::Base
  4. validates_presence_of :name
  5. has_many :projects
  6. has_many :work_orders
  7. has_one :user
  8.  
  9. accepts_nested_attributes_for :work_orders, :allow_destroy => true
  10. accepts_nested_attributes_for :user
  11. end
  12.  
  13. ## from my controller: pages_controller.rb
  14.  
  15. def order
  16. @client = Client.new # _with_user_and_work_orders
  17. @client.work_orders.build
  18. # @client.user.build #kills my view every time! ("NoMethodError in PagesController#order")
  19. end
  20.  
  21.  
  22. ## my view: order.haml
  23.  
  24. =error_messages_for :client
  25. -form_for @client do |order_form|
  26. #client
  27. %h2 Your Name or Company Name:
  28. =order_form.text_field :name, :class => "form", :size => "30"
  29. %hr
  30.  
  31. #user_creation
  32. -order_form.fields_for @user do |user_form| #If I use ":user" my view dies, claiming "The error occurred while evaluating nil.new_record?"
  33. =user_form.text_field :username
  34. =user_form.text_field :firstname
  35. =user_form.text_field :lastname
  36. =user_form.password_field :password
  37. =user_form.password_field :password_confirmation
  38.  
  39. #work_orders
  40. -order_form.fields_for :work_orders do |wo_form|
  41. %h2 Project Variety:
  42. =wo_form.select("variety", [["Article", 'article'], ["Blog Post/Entry", 'blog'], ["Press Release", 'press release' ], ["Other Website Content", 'other']], :class => "form")
  43. %h2 Project Title/Description:
  44. =wo_form.text_field :name, :class => "form", :size => "30"
  45. =wo_form.text_area :client_description, :class => "form", :size => "51x4"
  46. %hr.thin
  47.  
  48. =order_form.submit "Submit"
Add Comment
Please, Sign In to add comment