rails simple_form remote:true不会显示验证错误

时间:2018-10-26 18:14:05

标签: ruby-on-rails zurb-foundation simple-form zurb-foundation-6

我被铁轨卡住了,在地基上用遥控器显示:true,它不显示任何验证错误..任何帮助都将受到高度赞赏!

这是具有以下形式的显示:

<div class="reveal" id="new-trading-day-reveal" data-reveal>
  <div class="text-center">
    <h2>New Trading Day</h2>
  </div>
  <%= simple_form_for @trading_day, remote: true do |form| %>
    <div class="grid-x grid-padding-x">
      <div class="cell">
        <%= form.input :date, html5: true %>
      </div>
      <div class="cell">
        <%= form.button :submit, class: 'expanded' %>
      </div>
    </div>
  <% end %>
  <button class="close-button" data-close aria-label="Close modal" type="button">
    <span aria-hidden="true">&times;</span>
  </button>
</div>

这是相关的控制器代码:

class TradingDaysController < ApplicationController
  def new
    @trading_day = TradingDay.new
    authorize @trading_day
  end

  def create
    @trading_day = current_user.trading_days.create(trading_day_params)
    authorize @trading_day
    respond_to do |format|
      if @trading_day.save
        format.js { render layout: false, content_type: 'text/javascript' }
      else
        format.json {render json: @trading_day.errors, status: :unprocessable_entity}
      end
    end
  end
end

控制器确实响应422(如预期的那样)并给出以下答复:

{"date":["can't be blank"]}

尽管simple_form似乎没有发现错误...

我很高兴能提供帮助

非常感谢你们, 安德烈亚斯(Andreas)

0 个答案:

没有答案