Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/63.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rails 5客户端验证在Heroku上不起作用_Ruby On Rails_Ruby_Heroku_Ruby On Rails 5 - Fatal编程技术网

Ruby on rails Rails 5客户端验证在Heroku上不起作用

Ruby on rails Rails 5客户端验证在Heroku上不起作用,ruby-on-rails,ruby,heroku,ruby-on-rails-5,Ruby On Rails,Ruby,Heroku,Ruby On Rails 5,在开发过程中,我的客户端验证工作得很好,但是当我把它推给Heroku时,它们并没有运行。看起来javascript没有正确运行 模型仍然验证并拒绝错误的输入 我一直在搜索谷歌,尝试我遇到的任何解决方案,但都无济于事。我甚至为生产环境预编译了我的资产,并推送它们以查看这是否可行,但没有 这是我很长一段时间以来第一次使用Rails,所以我不确定您需要查看我的代码中的哪些部分来诊断问题,但如果您能提供帮助,我将不胜感激 编辑:添加模型和更多信息 我正在使用客户端验证gem 目前,我只是检查输入是否存在

在开发过程中,我的客户端验证工作得很好,但是当我把它推给Heroku时,它们并没有运行。看起来javascript没有正确运行

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

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

这是我很长一段时间以来第一次使用Rails,所以我不确定您需要查看我的代码中的哪些部分来诊断问题,但如果您能提供帮助,我将不胜感激

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

我正在使用
客户端验证
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
  • 对于您的app/assets/javascripts/application.js,请确保

    //=需要rails.validations

  • 站点示例显示,您的表单不需要使用remote:true

    • 据我所知,gem将处理ajax请求,因此您不需要手动将remote:true再次用于ajax

您不需要在
dev
中预编译。预编译在中自动完成heroku@illusionist是的,我本来没有这样做,但我遇到了一些问题,这表明了这一点。我将删除它们只是为了保持正常。请上传您的模型验证。您可以打开app/models/your_model.rb,并告诉我们哪些验证不起作用(更多详细信息)@widjajayd更新了问题。我有remote:true,所以我提交时页面不会重新加载,我删除了它,它发送了表单,但是下面的视图中没有短网址。没问题,伙计,谢谢你的帮助,哈哈。这快把我逼疯了。
<%= 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.