trestle
trestle copied to clipboard
fields_for, accepts_nested_attributes_for - showing AssociationTypeMismatch issue
class Restaurant < ApplicationRecord has_one :address has_one :location has_one :country end
class Address < ApplicationRecord belongs_to :restaurant accepts_nested_attributes_for :restaurant end
form do |restaurant| text_field :restaurant_name
row do
col(xs: 6) { text_field :business_hours }
col(xs: 6) { text_field :restaurant_image }
col(xs: 6) { text_field :first_name }
col(xs: 6) { text_field :last_name }
col(xs: 6) { text_field :email }
col(xs: 6) { text_area :payment_gateway_credentials }
col(xs: 6) { password_field :password }
col(xs: 6) { password_field :password_confirmation }
end
fields_for :address, restaurant.address || restaurant.build_address do
row do
col(xs: 6) { select :country_id, Country.all }
col(xs: 6) { text_field :address_line_1 }
col(xs: 6) { text_field :address_line_2 }
col(xs: 6) { text_field :city }
col(xs: 6) { text_field :state }
col(xs: 6) { text_field :postal_code }
end
end
fields_for :location, restaurant.location do
row do
col(xs: 6) { text_field :latitude }
col(xs: 6) { text_field :longitude }
col(xs: 6) { text_field :location_name }
end
end
end
try it
class Restaurant < ApplicationRecord
has_one :address
has_one :location
has_one :country
accepts_nested_attributes_for :address
end
class Address < ApplicationRecord
belongs_to :restaurant
end