Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## [plain_text]
- Trying to create a form that stores submitted data into more than one table
- Getting the following error: undefined method `address_1' for #<Customer:0xb7c6b2b0>
- ## customer.rb [ruby_on_rails]
- class Customer < ActiveRecord::Base
- has_many :addresses, :dependent => :destroy
- validates_presence_of :title, :forename, :surname, :company
- end
- ## address.rb
- class Address < ActiveRecord::Base
- belongs_to :customer
- end
- ##new.html.erb
- <h2>Register New Company</h2>
- <%= error_messages_for :customer %>
- <% form_for(@customer) do |f| %>
- <h3>Contact Information</h3>
- <p>
- <b>Title</b><br />
- <%= select(:customer, :title, ["Mr", "Mrs", "Miss", "Ms"]) %>
- </p>
- <p>
- <b>Forename</b><br />
- <%= f.text_field :forename %>
- </p>
- <p>
- <b>Surname</b><br />
- <%= f.text_field :surname %>
- </p>
- <p>
- <b>Company</b><br />
- <%= f.text_field :company %>
- </p>
- <p>
- <%= f.submit "Create" %>
- </p>
- <h3>Primary Address</h3>
- <p>
- <b>Address Line 1</b><br />
- <%= f.text_field :address_1 %>
- </p>
- <% end %>
- <%= link_to 'Back', customers_path %>
Add Comment
Please, Sign In to add comment