简单表单上的Rails 4客户端验证不能内联工作?

时间:2018-08-03 06:03:34

标签: ruby-on-rails ruby-on-rails-4 rubygems client-side-validation

嗨,我需要更多帮助。

我正在按照本教程使用client_side_validationRailcasts: Client Side Validations。似乎很容易使用,但是我找不到如何显示我的内联错误。

报告模型

Class Report < ActiveRecords::Base
   attr_accessor :producer_selected, producer_id
   belongs_to :producer
   validates :producer_selected, presence => true
   ....

报表控制器

Class ReportsController < ApplicationController
   def generate_clients
   @report = Report.new(report_params)
   @report.queue_status = "Completed"
   @report.created_by = current_user.id

   respond_to do |format|
     if @report.save

       @producer = Producer.find(params[:report][:producer_id])
       ....

       if @report.report_type == "Clients per Producer"
      requests = Request.from_date_range(params[:report][:from_due_date], params[:report][:to_due_date])
      @records = requests.records(params[:report][:producer_id]) 
    end
    format.html {
      outstrio = StringIO.new
      @report.update_attribute(:date_start, DateTime.now)
      p = render_to_string handlers: [:axlsx], formats: [:xlsx], template: "reports/create_clients"
      outstrio.write(p)
      @report.update_attribute(:date_end, DateTime.now)
      send_data outstrio.string, filename: "#{DateTime.now.to_date} #{@report.report_name}.xlsx"
    }
    format.json { render :show, status: :created, location: @report }
  else
    puts @report.errors.full_messages
    format.html { redirect_to :back, alert: 'Both dates must be filled up.' }
    format.json { render json: @report.errors, status: :unprocessable_entity }
  end
end
end

_clients_form.html.haml

= simple_form_for @report, :validate => true, url:generate_clients_reports_path do |f|
= f.error_notification
.form-inputs
.form-group.col-md-12
  =f.label :from_due_date, :label => "From:", class: "col-md-2 text-right", :style => "margin-top:6px;"
  =f.date_field :from_due_date, :as => :date, class: "range-control col-md-2"

  =f.label :to_due_date, :label => "To:", class: "col-md-2 text-right", :style => "margin-top:6px;"
  =f.date_field :to_due_date, :as => :date, class: "range-control col-md-2"

.form-group.col-md-12
  =f.input :report_type, :as => :select, :collection => @report_types, :wrapper => :field_multi8, :label_html => {:class => "col-md-2 text-right"}, :input_html => {:class => "form-control"}, :label => "Report Type:", :include_hidden => false, :include_blank => false

.form-group.col-md-12
  = f.input :producer_selected, :url => autocomplete_producer_search_string_requests_path, :required => :true, :as => :autocomplete, :wrapper => :field_multi8, :label_html => { :class => "col-md-2 text-right" }, :input_html => { :class => "form-control" }, :id_element => "#report_producer_id", :label => "Producer/Client :", :placeholder => "Find Producer", :update_elements => {}, :autofocus => true
  = f.input_field :producer_id, :as => :hidden

client_side_validations.rb

require 'client_side_validations/simple_form' if defined?(::SimpleForm)
require 'client_side_validations/formtastic' if defined?(::Formtastic)
 <label for="#{instance.send(:tag_id)}" class="message"></label>

 ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
   unless html_tag =~ /^<label/
     %{<div class="field_with_errors">#{html_tag}<label for="#{instance.send(:tag_id)}" class="message">#{instance.error_message.first}</label></div>}.html_safe
   else
     %{<div class="field_with_errors">#{html_tag}</div>}.html_safe
   end
 end
  • 宝石已安装在gemfile中
  • 导轨4.2.3

我正在做所有基本的事情,但是所有基本的验证也没有用。在脱离现场重点之后,将不会进行内联验证。

可能是什么问题?救命!

编辑:也尝试过this solution,但是它说找不到存储库。

0 个答案:

没有答案