Rails 5客户端验证不适用于Heroku

时间:2017-06-24 14:35:09

标签: ruby-on-rails ruby heroku ruby-on-rails-5

在开发中,我的客户端验证工作得很好,但是当我将它推送到Heroku时,它们没有运行。似乎javascript运行不正常。

该模型仍然验证并拒绝输入错误。

我一直在搜索谷歌尝试我遇到的任何解决方案但无济于事。我甚至为生产环境预编译了我的资产,并推动他们看看这是否有效但是没有。

这是我第一次使用Rails很长一段时间,所以我不完全确定我需要看到哪些部分代码来诊断问题,但任何帮助都会受到赞赏。

编辑:添加模型和更多信息

我正在使用client_side_validations gem

目前我只是检查输入的存在,然后使用正则表达式来确保它是一个URL。

class Url < ApplicationRecord
  after_create :generate_slug
  validates :given_url, presence: true
  validates_format_of :given_url, :with => /(http:\/\/www\.|https:\/\/www\.|http:\/\/|https:\/\/)?[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?\z/

  # Convert the ID to base36 to be used as the path
  def generate_slug
    self.slug = self.id.to_s(36)
    self.save
  end

  # construct the new URL
  def display_slug
    ENV['BASE_URL'] + self.slug
  end

end

以下是我视图中的表单

<%= form_for @url, validate: true, remote: true do |f| %>
    <div class ="input-group">
        <label hidden></label>
        <%= f.text_field :given_url, validate: {presence: true}, :class => "form-control", :placeholder => "Give me a link..." %>
        <span class="input-group-btn">
        <%= f.submit 'Go!', :class => "btn btn-primary btn-lg" %>
        </span>
     </div> <!-- input group -->
<% end %>

和部署日志

Total 0 (delta 0), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote: 
remote: -----> Node.js app detected
remote: 
remote: -----> Creating runtime environment
remote:        
remote:        NPM_CONFIG_LOGLEVEL=error
remote:        NPM_CONFIG_PRODUCTION=true
remote:        NODE_VERBOSE=false
remote:        NODE_ENV=production
remote:        NODE_MODULES_CACHE=true
remote: 
remote: -----> Installing binaries
remote:        engines.node (package.json):  unspecified
remote:        engines.npm (package.json):   unspecified (use default)
remote:        engines.yarn (package.json):  unspecified (use default)
remote:        
remote:        Resolving node version 6.x via semver.io...
remote:        Downloading and installing node 6.11.0...
remote:        Using default npm version: 3.10.10
remote:        Resolving yarn version (latest) via semver.io...
remote:        Downloading and installing yarn (0.24.5)...
remote:        Installed yarn 0.24.5
remote: 
remote: -----> Restoring cache
remote:        Loading 2 from cacheDirectories (default):
remote:        - node_modules (not cached - skipping)
remote:        - bower_components (not cached - skipping)
remote: 
remote: -----> Building dependencies
remote:        Installing node modules (yarn.lock)
remote:        yarn install v0.24.5
remote:        [1/4] Resolving packages...
remote:        [2/4] Fetching packages...
remote:        [3/4] Linking dependencies...
remote:        [4/4] Building fresh packages...
remote:        Done in 0.07s.
remote: 
remote: -----> Caching build
remote:        Clearing previous node cache
remote:        Saving 2 cacheDirectories (default):
remote:        - node_modules (nothing to cache)
remote:        - bower_components (nothing to cache)
remote: 
remote: -----> Build succeeded!
remote:  !     This app may not specify any way to start a node process
remote:        https://devcenter.heroku.com/articles/nodejs-support#default-web-process-type
remote: 
remote: -----> Ruby app detected
remote: -----> Compiling Ruby/Rails
remote: -----> Using Ruby version: ruby-2.3.4
remote: -----> Installing dependencies using bundler 1.15.1
remote:        Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin -j4 --deployment
remote:        Fetching gem metadata from https://rubygems.org/.........
remote:        Fetching version metadata from https://rubygems.org/..
remote:        Fetching dependency metadata from https://rubygems.org/.
remote:        Using rake 12.0.0
remote:        Using concurrent-ruby 1.0.5
remote:        Using i18n 0.8.4
remote:        Using minitest 5.10.2
remote:        Using thread_safe 0.3.6
remote:        Using builder 3.2.3
remote:        Using erubi 1.6.0
remote:        Using mini_portile2 2.2.0
remote:        Using rack 2.0.3
remote:        Using nio4r 2.1.0
remote:        Using websocket-extensions 0.1.2
remote:        Using mime-types-data 3.2016.0521
remote:        Using arel 8.0.0
remote:        Using method_source 0.8.2
remote:        Using thor 0.19.4
remote:        Using bundler 1.15.1
remote:        Using pg 0.21.0
remote:        Using puma 3.9.1
remote:        Using sass 3.4.24
remote:        Using tilt 2.0.7
remote:        Using execjs 2.7.0
remote:        Using coffee-script-source 1.12.2
remote:        Using turbolinks-source 5.0.3
remote:        Using multi_json 1.12.1
remote:        Using regexp_parser 0.4.3
remote:        Using nokogiri 1.8.0
remote:        Using websocket-driver 0.6.5
remote:        Using mime-types 3.1
remote:        Using tzinfo 1.2.3
remote:        Using rack-test 0.6.3
remote:        Using sprockets 3.7.1
remote:        Using figaro 1.1.1
remote:        Using uglifier 3.2.0
remote:        Using autoprefixer-rails 7.1.1.2
remote:        Using turbolinks 5.0.1
remote:        Using coffee-script 2.4.1
remote:        Using mail 2.6.6
remote:        Using js_regex 1.2.3
remote:        Using activesupport 5.1.1
remote:        Using loofah 2.0.3
remote:        Using rails-dom-testing 2.0.3
remote:        Using globalid 0.4.0
remote:        Using activemodel 5.1.1
remote:        Using jbuilder 2.7.0
remote:        Using rails-html-sanitizer 1.0.3
remote:        Using bootstrap 4.0.0.alpha6
remote:        Using activejob 5.1.1
remote:        Using activerecord 5.1.1
remote:        Using actionview 5.1.1
remote:        Using actionpack 5.1.1
remote:        Using actioncable 5.1.1
remote:        Using actionmailer 5.1.1
remote:        Using railties 5.1.1
remote:        Using sprockets-rails 3.2.0
remote:        Using jquery-rails 4.3.1
remote:        Using coffee-rails 4.2.2
remote:        Using rails 5.1.1
remote:        Using sass-rails 5.0.6
remote:        Using client_side_validations 9.3.3
remote:        Bundle complete! 20 Gemfile dependencies, 59 gems now installed.
remote:        Gems in the groups development and test were not installed.
remote:        Bundled gems are installed into ./vendor/bundle.
remote:        Bundle completed (2.69s)
remote:        Cleaning up the bundler cache.
remote:        Detected manifest file, assuming assets were compiled locally
remote: 
remote: ###### WARNING:
remote:        You have not declared a Ruby version in your Gemfile.
remote:        To set your Ruby version add this line to your Gemfile:
remote:        ruby '2.3.4'
remote:        # See https://devcenter.heroku.com/articles/ruby-versions for more information.
remote: 
remote: ###### WARNING:
remote:        No Procfile detected, using the default web server.
remote:        We recommend explicitly declaring how to boot your server process via a Procfile.
remote:        https://devcenter.heroku.com/articles/ruby-default-web-server
remote: 
remote: -----> Discovering process types
remote:        Procfile declares types     -> (none)
remote:        Default types for buildpack -> console, rake, web, worker
remote: 
remote: -----> Compressing...
remote:        Done: 40M
remote: -----> Launching...
remote:        Released v25
remote:        https://fathomless-plateau-97011.herokuapp.com/ deployed to Heroku
remote: 
remote: Verifying deploy... done.

1 个答案:

答案 0 :(得分:1)

  • 对于您的app / assets / javascripts / application.js,请确保您有

    // = require rails.validations

  • 网站示例显示无需使用remote:true,用于

    的表单
    • 我理解gem会处理ajax请求,所以你不需要再次为了ajax设置remote:true
相关问题