ruby on rails - how to leave the field filled with fields_for? -
i have problem : when customer enters shipping , billing informations in form, fields of address model lose information if page reloaded. works other fields, email, included directly in order model. how leave fields filled after reloading ?
here's new.html.erb file :
<%= form_for @order |f| %> <ul> <% @order.errors.each_with_index |msg, i| %> <li><%= msg[1] %></li> <% end %> </ul> <%= f.text_field :email, placeholder: "email" %> <%= f.fields_for :shipping_address_attributes |sa| %> <%= sa.text_field :first_name, placeholder: "firstname" %> <%= sa.text_field :last_name, placeholder: "name", autocomplete: true %> <%= sa.text_field :address1, placeholder: "address", autocomplete: true %> #etc. <% end %> <p><%= f.submit 'next step' %></p> <% end %>
my models :
class order < activerecord::base belongs_to :billing_address, :class_name => "address" belongs_to :shipping_address, :class_name => "address" accepts_nested_attributes_for :shipping_address accepts_nested_attributes_for :billing_address, reject_if: :bill_to_shipping_address class address < activerecord::base belongs_to :user has_many :billing_addresses, :class_name => "order", :foreign_key => "billing_address_id", dependent: :nullify has_many :shipping_addresses, :class_name => "order", :foreign_key => "shipping_address_id", dependent: :nullify validates_presence_of :first_name, :last_name, :address1, :city, :country, :phone, :postal
and order_controller.rb:
def new @user = current_user @order_items = current_order.order_items @order = current_order @amount = @order.subtotal end def update @order_items = current_order.order_items @order = current_order if @order.update(order_params) redirect_to recapitulatif_de_la_commande_path else redirect_to(:back) end end
edit
maybe error due fact order not linked shipping address before update action ? works if address model validate presence of each attributes.
any idea ?
Comments
Post a Comment