Guest User

Untitled

a guest
Apr 23rd, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. ## [plain_text]
  2. Trying to create a form that stores submitted data into more than one table
  3. Getting the following error: undefined method `address_1' for #<Customer:0xb7c6b2b0>
  4.  
  5. ## customer.rb [ruby_on_rails]
  6. class Customer < ActiveRecord::Base
  7. has_many :addresses, :dependent => :destroy
  8. validates_presence_of :title, :forename, :surname, :company
  9. end
  10.  
  11. ## address.rb
  12. class Address < ActiveRecord::Base
  13. belongs_to :customer
  14. end
  15.  
  16. ##new.html.erb
  17. <h2>Register New Company</h2>
  18. <%= error_messages_for :customer %>
  19. <% form_for(@customer) do |f| %>
  20. <h3>Contact Information</h3>
  21. <p>
  22. <b>Title</b><br />
  23. <%= select(:customer, :title, ["Mr", "Mrs", "Miss", "Ms"]) %>
  24. </p>
  25. <p>
  26. <b>Forename</b><br />
  27. <%= f.text_field :forename %>
  28. </p>
  29. <p>
  30. <b>Surname</b><br />
  31. <%= f.text_field :surname %>
  32. </p>
  33. <p>
  34. <b>Company</b><br />
  35. <%= f.text_field :company %>
  36. </p>
  37. <p>
  38. <%= f.submit "Create" %>
  39. </p>
  40. <h3>Primary Address</h3>
  41. <p>
  42. <b>Address Line 1</b><br />
  43. <%= f.text_field :address_1 %>
  44. </p>
  45. <% end %>
  46.  
  47. <%= link_to 'Back', customers_path %>
Add Comment
Please, Sign In to add comment