0

I have to add a association form on Spree Return Authorization edit page and for that I have added code in overrides/spree/return_authorizations/_form/add_custom_tracker.html.erb.deface

<!-- insert_before 'erb[loud]:contains("f.field_container :stock_location")' -->


    <%= f.field_container :easypost_tracker do %>
      <%= f.fields_for @return_authorization.build_custom_tracker do |tracker| %>
        <%= tracker.label :tracking_code %>
        <%= tracker.text_field :tracking_code, class: 'fullwidth' %>

        <%= tracker.label :carrier %>
        <%= tracker.text_field :carrier, class: 'fullwidth' %>
      <% end %>
    <% end %>

Added association also and also permit params in spree.rb

base.has_one :custom_tracker, class_name: 'Custom::Tracker',
                                foreign_key: :spree_return_authorization_id
base.accepts_nested_attributes_for :custom_tracker

config/spree.rb

Spree::PermittedAttributes.return_authorization_attributes.push custom_tracker: [:id, :tracking_code, :carrier]

Form appearing on view fine but when I submit form its giving an error

ActiveRecord::AssociationTypeMismatch in Spree::Admin::ReturnAuthorizationsController#update
Easypost::Tracker(#286980) expected, got {"tracking_code"=>"5656", "carrier"=>"UPS"} which is an instance of ActiveSupport::HashWithIndifferentAccess(#295580)
Haseeb Ahmad
  • 7,914
  • 12
  • 55
  • 133

0 Answers0