Rails验证接受格式错误中的结果

时间:2015-12-04 22:14:24

标签: ruby-on-rails-4

在我的作者模型中,我正在尝试验证条款是否被接受。

在架构中,我将字段tos作为布尔值。

在模型中,我有这个用于验证:

validates_acceptance_of :tos, :accept => true

以我的形式:

<%= content_for(:the_links) do %>
  I agree to the <%= link_to "Terms of Service", tos_path,:remote => true %>
  and <%=link_to "Privacy Policy", "#", :remote => true%>
<% end %>

<%= simple_form_for(@author) do |f| %>
    <%= f.input :tos, :as => :boolean, label: false, boolean_style: :inline, :hint => content_for(:the_links)%> 
    <%= f.button :submit %>
<% end %>

我收到的错误:

ActionController::UnknownFormat in AuthorsController#create
ActionController::UnknownFormat

参数看起来像这样:

{"utf8"=>"✓",
 "author"=>{
 "tos"=>"0"},
 "commit"=>"Create Author"}

我的问题似乎与此问题略有不同: Validates acceptance always failing

但我也尝试过:

  • 从数据库中删除属性
  • 将验证更改为:validates :terms, :acceptance => {:accept => true}

然而,我仍然得到格式错误。

添加创建动作

  def create
    @author = Author.new(author_params)
    @author.user_id = current_user.id

    respond_to do |format|
      if @author.save

        merchant_account_params = {
        :individual => {
          :first_name => @author.first_name,
          :last_name => @author.last_name,
          :email => current_user.email,
          :date_of_birth => @author.dob,
          :ssn => @author.ssn,
          :address => {
            :street_address => @author.indiv_street,
            :locality => @author.indiv_city,
            :region => @author.indiv_state,
            :postal_code => @author.indiv_postal_code
          }
        },
        :business => {
          :legal_name => @author.legal_name,
          :dba_name => @author.dba,
          :tax_id => @author.ein,
          :address => {
            :street_address => @author.bus_street,
            :locality => @author.bus_city,
            :region => @author.bus_state,
            :postal_code => @author.bus_postal_code
          }
        },
        :funding => {
          :destination => "email",
          :email => @author.venmo_email,
        },
        :tos_accepted => @author.tos,
        :master_merchant_account_id => BT_SANDBOX_MASTER_MERCHANT,
        :id => @author.id
      }
      result = Braintree::MerchantAccount.create(merchant_account_params)
        if result.success?
          @author.update(:status=>result.merchant_account.status)  
          format.html { redirect_to @author, notice: 'Author was successfully created.' }
          format.json { render :show, status: :created, location: @author }
        else
          format.html { render :new }
          format.json { render json: @author.errors, status: :unprocessable_entity }
        end
      end
    end
  end

0 个答案:

没有答案