我在将我的应用程序推送到 Heroku 时遇到问题。下面是我尝试使用“git push heroku master”时的终端输出
Counting objects: 22, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (22/22), done.
Writing objects: 100% (22/22), 2.16 KiB | 2.16 MiB/s, done.
Total 22 (delta 15), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Ruby app detected
remote: -----> Compiling Ruby/Rails
remote: -----> Using Ruby version: ruby-2.5.1
remote: -----> Installing dependencies using bundler 1.15.2
remote: Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin -j4 --deployment
remote: Warning: the running version of Bundler (1.15.2) is older than the version that created the lockfile (1.16.4). We suggest you upgrade to the latest version of Bundler by running `gem install bundler`.
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.3.1
remote: Using concurrent-ruby 1.0.5
remote: Using minitest 5.11.3
remote: Using thread_safe 0.3.6
remote: Using builder 3.2.3
remote: Using erubi 1.7.1
remote: Using mini_portile2 2.3.0
remote: Using crass 1.0.4
remote: Using rack 2.0.5
remote: Using nio4r 2.3.1
remote: Using websocket-extensions 0.1.3
remote: Using mini_mime 1.0.0
remote: Using arel 9.0.0
remote: Using mimemagic 0.3.2
remote: Using bcrypt 3.1.12
remote: Using msgpack 1.2.4
remote: Using bundler 1.15.2
remote: Using cancancan 2.2.0
remote: Using coffee-script-source 1.12.2
remote: Using execjs 2.7.0
remote: Using method_source 0.9.0
remote: Using thor 0.20.0
remote: Using orm_adapter 0.5.0
remote: Using ffi 1.9.25
remote: Using multi_json 1.13.1
remote: Using pg 1.0.0
remote: Using puma 3.12.0
remote: Using rb-fsevent 0.10.3
remote: Using tilt 2.0.8
remote: Using turbolinks-source 5.1.0
remote: Fetching will_paginate 3.1.6
remote: Using tzinfo 1.2.5
remote: Using nokogiri 1.8.4
remote: Using i18n 1.1.0
remote: Using rack-test 1.1.0
remote: Using warden 1.2.7
remote: Using sprockets 3.7.2
remote: Using mail 2.7.0
remote: Using websocket-driver 0.7.0
remote: Using marcel 0.3.2
remote: Using coffee-script 2.4.1
remote: Using uglifier 4.1.18
remote: Using rb-inotify 0.9.10
remote: Using bootsnap 1.3.1
remote: Using turbolinks 5.1.1
remote: Using loofah 2.2.2
remote: Using activesupport 5.2.1
remote: Using sass-listen 4.0.0
remote: Using rails-html-sanitizer 1.0.4
remote: Using rails-dom-testing 2.0.3
remote: Using globalid 0.4.1
remote: Using activemodel 5.2.1
remote: Using jbuilder 2.7.0
remote: Using sass 3.5.7
remote: Using actionview 5.2.1
remote: Using activejob 5.2.1
remote: Using activerecord 5.2.1
remote: Using actionpack 5.2.1
remote: Using actioncable 5.2.1
remote: Using actionmailer 5.2.1
remote: Using activestorage 5.2.1
remote: Using railties 5.2.1
remote: Using sprockets-rails 3.2.1
remote: Using coffee-rails 4.2.2
remote: Using responders 2.4.0
remote: Using jquery-rails 4.3.3
remote: Using rails 5.2.1
remote: Using sass-rails 5.0.7
remote: Using devise 4.5.0
remote: Installing will_paginate 3.1.6
remote: Bundle complete! 20 Gemfile dependencies, 69 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 (3.33s)
remote: Cleaning up the bundler cache.
remote: Warning: the running version of Bundler (1.15.2) is older than the version that created the lockfile (1.16.4). We suggest you upgrade to the latest version of Bundler by running `gem install bundler`.
remote: The latest bundler is 1.16.4, but you are currently running 1.15.2.
remote: To update, run `gem install bundler`
remote: -----> Installing node-v8.10.0-linux-x64
remote: -----> Detecting rake tasks
remote: -----> Preparing app for Rails asset pipeline
remote: Running: rake assets:precompile
remote: Yarn executable was not detected in the system.
remote: Download Yarn at https://yarnpkg.com/en/docs/install
remote: I, [2018-09-10T13:46:40.231019 #394] INFO -- : Writing /tmp/build_d03dd820f3a6d398522db8ceeafe1812/public/assets/0-2f224f1c26eb187a4e48a623951f607419e6582b45063cb2a247ed92b2dee9fd.png
remote: I, [2018-09-10T13:46:40.233643 #394] INFO -- : Writing /tmp/build_d03dd820f3a6d398522db8ceeafe1812/public/assets/1-e939388a981a2f5d794dc2c45f36224116d5d457d766baccfbafaab654933b89.png
remote: I, [2018-09-10T13:46:40.236052 #394] INFO -- : Writing /tmp/build_d03dd820f3a6d398522db8ceeafe1812/public/assets/2-c97fc71270db08081907559965118e78d296b15ead96645a309f0098bbfc9ab4.png
remote: I, [2018-09-10T13:46:40.238092 #394] INFO -- : Writing /tmp/build_d03dd820f3a6d398522db8ceeafe1812/public/assets/3-0fd2895b84fe6c3fe38b92e1282c65fab8b7b74fc6e92f8827d65451910d6ba4.png
remote: I, [2018-09-10T13:46:40.240552 #394] INFO -- : Writing /tmp/build_d03dd820f3a6d398522db8ceeafe1812/public/assets/4-de0b5807f5a4eeb9e90e6d171904ec57848010b65d20494419565f8424884c60.png
remote: I, [2018-09-10T13:46:40.242957 #394] INFO -- : Writing /tmp/build_d03dd820f3a6d398522db8ceeafe1812/public/assets/5-8dd2b09aa49f1caf833c87cc4bcb7700d31dc842e82c2fa60ddf84635af5693d.png
remote: I, [2018-09-10T13:46:40.249959 #394] INFO -- : Writing /tmp/build_d03dd820f3a6d398522db8ceeafe1812/public/assets/cancel-custom-off-e7d2ac9d0d0574c9b41e3f4b838a258d31f491f3ce616b695295b5754897528d.png
remote: I, [2018-09-10T13:46:40.252393 #394] INFO -- : Writing /tmp/build_d03dd820f3a6d398522db8ceeafe1812/public/assets/cancel-custom-on-e801e71a9008b085e080ca40ded7c86ee0aebcc5baee50f5c8282a1d4d14404d.png
remote: I, [2018-09-10T13:46:40.254896 #394] INFO -- : Writing /tmp/build_d03dd820f3a6d398522db8ceeafe1812/public/assets/cancel-off-5758f74356b87443c8dd8d07a98b4be8b9e5b0a6304baf27bbd2b99d8e02d01c.png
remote: I, [2018-09-10T13:46:40.256937 #394] INFO -- : Writing /tmp/build_d03dd820f3a6d398522db8ceeafe1812/public/assets/cancel-on-52afce0580c4df0b09e2302d54750e9d7b882b7c6c6847a16c98f606b2451389.png
remote: I, [2018-09-10T13:46:40.363704 #394] INFO -- : Writing /tmp/build_d03dd820f3a6d398522db8ceeafe1812/public/assets/off-12ebbed5d82fd3c5e97d907750d59738e230e120a2c6310a75f698f4e9a02d43.png
remote: I, [2018-09-10T13:46:40.366453 #394] INFO -- : Writing /tmp/build_d03dd820f3a6d398522db8ceeafe1812/public/assets/on-a138853be3ec7e6cb69a9e761fe1a2fe5985d17c2463a277f8da4a5ca7598039.png
remote: I, [2018-09-10T13:46:40.379200 #394] INFO -- : Writing /tmp/build_d03dd820f3a6d398522db8ceeafe1812/public/assets/star-half-mono-2faa84c4e49ad062e611850004ec93ec89760d221400969a70918b4248b333df.png
remote: I, [2018-09-10T13:46:40.381479 #394] INFO -- : Writing /tmp/build_d03dd820f3a6d398522db8ceeafe1812/public/assets/star-half-808ffaeee4006e4930f89f5dcf46f603eb173ecc365b8f3df2b822bb6747c0b8.png
remote: I, [2018-09-10T13:46:40.383760 #394] INFO -- : Writing /tmp/build_d03dd820f3a6d398522db8ceeafe1812/public/assets/star-off-cf9b07584547d5d561dfac9cdbf7b6a530cb72a1b7a1096411966036c4017d38.png
remote: I, [2018-09-10T13:46:40.385981 #394] INFO -- : Writing /tmp/build_d03dd820f3a6d398522db8ceeafe1812/public/assets/star-on-88233ad1abcd2282b53edb9465a6bef42fd32de319f014e4059353e4fd8a7e0a.png
remote: rake aborted!
remote: Uglifier::Error: Unexpected token name «scoreName», expected punc «,». To use ES6 syntax, harmony mode must be enabled with Uglifier.new(:harmony => true).
remote: /tmp/build_d03dd820f3a6d398522db8ceeafe1812/vendor/bundle/ruby/2.5.0/gems/uglifier-4.1.18/lib/uglifier.rb:234:in `parse_result'
remote: /tmp/build_d03dd820f3a6d398522db8ceeafe1812/vendor/bundle/ruby/2.5.0/gems/uglifier-4.1.18/lib/uglifier.rb:216:in `run_uglifyjs'
remote: /tmp/build_d03dd820f3a6d398522db8ceeafe1812/vendor/bundle/ruby/2.5.0/gems/uglifier-4.1.18/lib/uglifier.rb:168:in `compile'
remote: /tmp/build_d03dd820f3a6d398522db8ceeafe1812/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/uglifier_compressor.rb:53:in `call'
remote: /tmp/build_d03dd820f3a6d398522db8ceeafe1812/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/uglifier_compressor.rb:28:in `call'
remote: /tmp/build_d03dd820f3a6d398522db8ceeafe1812/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/processor_utils.rb:75:in `call_processor
remote: /tmp/build_d03dd820f3a6d398522db8ceeafe1812/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/processor_utils.rb:57:in `block in call_processors'
remote: /tmp/build_d03dd820f3a6d398522db8ceeafe1812/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/processor_utils.rb:56:in `reverse_each'
remote: /tmp/build_d03dd820f3a6d398522db8ceeafe1812/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/processor_utils.rb:56:in `call_processors'
remote: /tmp/build_d03dd820f3a6d398522db8ceeafe1812/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/loader.rb:134:in `load_from_unloaded'
remote: /tmp/build_d03dd820f3a6d398522db8ceeafe1812/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/loader.rb:60:in `block in load'
remote: /tmp/build_d03dd820f3a6d398522db8ceeafe1812/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/loader.rb:317:in `fetch_asset_from_dependency_cache'
remote: /tmp/build_d03dd820f3a6d398522db8ceeafe1812/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/loader.rb:44:in `load'
remote: /tmp/build_d03dd820f3a6d398522db8ceeafe1812/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/cached_environment.rb:20:in `block in initialize'
remote: /tmp/build_d03dd820f3a6d398522db8ceeafe1812/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/cached_environment.rb:47:in `load'
remote: /tmp/build_d03dd820f3a6d398522db8ceeafe1812/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/base.rb:66:in `find_asset'
remote: /tmp/build_d03dd820f3a6d398522db8ceeafe1812/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/base.rb:73:in `find_all_linked_assets'
remote: /tmp/build_d03dd820f3a6d398522db8ceeafe1812/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/manifest.rb:142:in `block in find'
remote: /tmp/build_d03dd820f3a6d398522db8ceeafe1812/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/legacy.rb:114:in `block (2 levels) in logical_paths'
remote: /tmp/build_d03dd820f3a6d398522db8ceeafe1812/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/path_utils.rb:228:in `block in stat_tree
remote: /tmp/build_d03dd820f3a6d398522db8ceeafe1812/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/path_utils.rb:212:in `block in stat_directory'
remote: /tmp/build_d03dd820f3a6d398522db8ceeafe1812/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/path_utils.rb:209:in `each'
remote: /tmp/build_d03dd820f3a6d398522db8ceeafe1812/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/path_utils.rb:209:in `stat_directory'
remote: /tmp/build_d03dd820f3a6d398522db8ceeafe1812/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/path_utils.rb:227:in `stat_tree'
remote: /tmp/build_d03dd820f3a6d398522db8ceeafe1812/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/legacy.rb:105:in `each'
remote: /tmp/build_d03dd820f3a6d398522db8ceeafe1812/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/legacy.rb:105:in `block in logical_paths
remote: /tmp/build_d03dd820f3a6d398522db8ceeafe1812/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/legacy.rb:104:in `each'
remote: /tmp/build_d03dd820f3a6d398522db8ceeafe1812/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/legacy.rb:104:in `logical_paths'
remote: /tmp/build_d03dd820f3a6d398522db8ceeafe1812/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/manifest.rb:140:in `find'
remote: /tmp/build_d03dd820f3a6d398522db8ceeafe1812/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/manifest.rb:186:in `compile'
remote: /tmp/build_d03dd820f3a6d398522db8ceeafe1812/vendor/bundle/ruby/2.5.0/gems/sprockets-rails-3.2.1/lib/sprockets/rails/task.rb:68:in `block (3 levels) in define'
remote: /tmp/build_d03dd820f3a6d398522db8ceeafe1812/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/rake/sprocketstask.rb:147:in `with_logger'
remote: /tmp/build_d03dd820f3a6d398522db8ceeafe1812/vendor/bundle/ruby/2.5.0/gems/sprockets-rails-3.2.1/lib/sprockets/rails/task.rb:67:in `block (2 levels) in define'
remote: /tmp/build_d03dd820f3a6d398522db8ceeafe1812/vendor/bundle/ruby/2.5.0/gems/rake-12.3.1/exe/rake:27:in `<top (required)>'
remote: Tasks: TOP => assets:precompile
remote: (See full trace by running task with --trace)
remote:
remote: !
remote: ! Precompiling assets failed.
remote: !
remote: ! Push rejected, failed to compile Ruby app.
remote:
remote: ! Push failed
remote: Verifying deploy...
remote:
remote: ! Push rejected to whispering-springs-21097.
remote:
To https://git.heroku.com/whispering-springs-21097.git
! [remote rejected] master -> master (pre-receive hook declined)
下面也是我的gemfile。
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.5.1'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.2.1'
# Use sqlite3 as the database for Active Record
group :development, :test do
gem 'sqlite3'
end
# Use Puma as the app server
gem 'puma', '~> 3.11'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'mini_racer', platforms: :ruby
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
gem 'jquery-rails', '~> 4.3', '>= 4.3.3'
# Use ActiveStorage variant
# gem 'mini_magick', '~> 4.8'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.1.0', require: false
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
end
group :development do
# Access an interactive console on exception pages or by calling 'console' anywhere in the code.
gem 'web-console', '>= 3.3.0'
gem 'listen', '>= 3.0.5', '< 3.2'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
gem 'devise', '~> 4.5'
gem 'cancancan', '~> 2.2'
gem 'will_paginate', '~> 3.1.0'
group :production do
gem 'pg'
end
我可以毫无问题地将代码推送到github。然而,Heroku 似乎不断提出同样的问题。
下面也是我的production.rb文件。
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
config.action_mailer.default_url_options = { host: "whispering-springs-21097
.herokuapp.com" }
# Code is not reloaded between requests.
config.cache_classes = true
# Eager load code on boot. This eager loads most of Rails and
# your application in memory, allowing both threaded web servers
# and those relying on copy on write to perform better.
# Rake tasks automatically ignore this option for performance.
config.eager_load = true
# Full error reports are disabled and caching is turned on.
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
# Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"]
# or in config/master.key. This key is used to decrypt credentials (and other encrypted files).
# config.require_master_key = true
# Disable serving static files from the `/public` folder by default since
# Apache or NGINX already handles this.
config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
# Compress JavaScripts and CSS.
config.assets.js_compressor = :uglifier
# config.assets.css_compressor = :sass
# Do not fallback to assets pipeline if a precompiled asset is missed.
config.assets.compile = true
# `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb
# Enable serving of images, stylesheets, and JavaScripts from an asset server.
# config.action_controller.asset_host = 'http://assets.example.com'
# Specifies the header that your server uses for sending files.
# config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX
# Store uploaded files on the local file system (see config/storage.yml for options)
config.active_storage.service = :local
# Mount Action Cable outside main process or domain
# config.action_cable.mount_path = nil
# config.action_cable.url = 'wss://example.com/cable'
# config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ]
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
# config.force_ssl = true
# Use the lowest log level to ensure availability of diagnostic information
# when problems arise.
config.log_level = :debug
# Prepend all log lines with the following tags.
config.log_tags = [ :request_id ]
# Use a different cache store in production.
# config.cache_store = :mem_cache_store
# Use a real queuing backend for Active Job (and separate queues per environment)
# config.active_job.queue_adapter = :resque
# config.active_job.queue_name_prefix = "nameofapp_#{Rails.env}"
config.action_mailer.perform_caching = false
# Ignore bad email addresses and do not raise email delivery errors.
# Set this to true and configure the email server for immediate delivery to raise delivery errors.
# config.action_mailer.raise_delivery_errors = false
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation cannot be found).
config.i18n.fallbacks = true
# Send deprecation notices to registered listeners.
config.active_support.deprecation = :notify
# Use default logging formatter so that PID and timestamp are not suppressed.
config.log_formatter = ::Logger::Formatter.new
# Use a different logger for distributed setups.
# require 'syslog/logger'
# config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')
if ENV["RAILS_LOG_TO_STDOUT"].present?
logger = ActiveSupport::Logger.new(STDOUT)
logger.formatter = config.log_formatter
config.logger = ActiveSupport::TaggedLogging.new(logger)
end
# Do not dump schema after migrations.
config.active_record.dump_schema_after_migration = false
end
如有任何建议,我们将不胜感激。
最佳答案
Uglifier::Error: Unexpected token name «scoreName», expected punc «,». To use ES6 syntax, harmony mode must be enabled with Uglifier.new(:harmony => true)
你只需要改变
config.assets.js_compressor = :uglifier
到
config.assets.js_compressor = Uglifier.new(harmony: true)
在 production.rb(或适当的 Heroku 环境,如 staging.rb,在构建管道中抛出错误)
关于ruby-on-rails - Heroku 推送问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52259494/
我正在学习如何使用Nokogiri,根据这段代码我遇到了一些问题:require'rubygems'require'mechanize'post_agent=WWW::Mechanize.newpost_page=post_agent.get('http://www.vbulletin.org/forum/showthread.php?t=230708')puts"\nabsolutepathwithtbodygivesnil"putspost_page.parser.xpath('/html/body/div/div/div/div/div/table/tbody/tr/td/div
总的来说,我对ruby还比较陌生,我正在为我正在创建的对象编写一些rspec测试用例。许多测试用例都非常基础,我只是想确保正确填充和返回值。我想知道是否有办法使用循环结构来执行此操作。不必为我要测试的每个方法都设置一个assertEquals。例如:describeitem,"TestingtheItem"doit"willhaveanullvaluetostart"doitem=Item.new#HereIcoulddotheitem.name.shouldbe_nil#thenIcoulddoitem.category.shouldbe_nilendend但我想要一些方法来使用
我有一个字符串input="maybe(thisis|thatwas)some((nice|ugly)(day|night)|(strange(weather|time)))"Ruby中解析该字符串的最佳方法是什么?我的意思是脚本应该能够像这样构建句子:maybethisissomeuglynightmaybethatwassomenicenightmaybethiswassomestrangetime等等,你明白了......我应该一个字符一个字符地读取字符串并构建一个带有堆栈的状态机来存储括号值以供以后计算,还是有更好的方法?也许为此目的准备了一个开箱即用的库?
我有一个Ruby程序,它使用rubyzip压缩XML文件的目录树。gem。我的问题是文件开始变得很重,我想提高压缩级别,因为压缩时间不是问题。我在rubyzipdocumentation中找不到一种为创建的ZIP文件指定压缩级别的方法。有人知道如何更改此设置吗?是否有另一个允许指定压缩级别的Ruby库? 最佳答案 这是我通过查看rubyzip内部创建的代码。level=Zlib::BEST_COMPRESSIONZip::ZipOutputStream.open(zip_file)do|zip|Dir.glob("**/*")d
类classAprivatedeffooputs:fooendpublicdefbarputs:barendprivatedefzimputs:zimendprotecteddefdibputs:dibendendA的实例a=A.new测试a.foorescueputs:faila.barrescueputs:faila.zimrescueputs:faila.dibrescueputs:faila.gazrescueputs:fail测试输出failbarfailfailfail.发送测试[:foo,:bar,:zim,:dib,:gaz].each{|m|a.send(m)resc
很好奇,就使用rubyonrails自动化单元测试而言,你们正在做什么?您是否创建了一个脚本来在cron中运行rake作业并将结果邮寄给您?git中的预提交Hook?只是手动调用?我完全理解测试,但想知道在错误发生之前捕获错误的最佳实践是什么。让我们理所当然地认为测试本身是完美无缺的,并且可以正常工作。下一步是什么以确保他们在正确的时间将可能有害的结果传达给您? 最佳答案 不确定您到底想听什么,但是有几个级别的自动代码库控制:在处理某项功能时,您可以使用类似autotest的内容获得关于哪些有效,哪些无效的即时反馈。要确保您的提
这似乎应该有一个直截了当的答案,但在Google上花了很多时间,所以我找不到它。这可能是缺少正确关键字的情况。在我的RoR应用程序中,我有几个模型共享一种特定类型的字符串属性,该属性具有特殊验证和其他功能。我能想到的最接近的类似示例是表示URL的字符串。这会导致模型中出现大量重复(甚至单元测试中会出现更多重复),但我不确定如何让它更DRY。我能想到几个可能的方向...按照“validates_url_format_of”插件,但这只会让验证干给这个特殊的字符串它自己的模型,但这看起来很像重溶液为这个特殊的字符串创建一个ruby类,但是我如何得到ActiveRecord关联这个类模型
假设我做了一个模块如下:m=Module.newdoclassCendend三个问题:除了对m的引用之外,还有什么方法可以访问C和m中的其他内容?我可以在创建匿名模块后为其命名吗(就像我输入“module...”一样)?如何在使用完匿名模块后将其删除,使其定义的常量不再存在? 最佳答案 三个答案:是的,使用ObjectSpace.此代码使c引用你的类(class)C不引用m:c=nilObjectSpace.each_object{|obj|c=objif(Class===objandobj.name=~/::C$/)}当然这取决于
我试图在一个项目中使用rake,如果我把所有东西都放到Rakefile中,它会很大并且很难读取/找到东西,所以我试着将每个命名空间放在lib/rake中它自己的文件中,我添加了这个到我的rake文件的顶部:Dir['#{File.dirname(__FILE__)}/lib/rake/*.rake'].map{|f|requiref}它加载文件没问题,但没有任务。我现在只有一个.rake文件作为测试,名为“servers.rake”,它看起来像这样:namespace:serverdotask:testdoputs"test"endend所以当我运行rakeserver:testid时
出于纯粹的兴趣,我很好奇如何按顺序创建PI,而不是在过程结果之后生成数字,而是让数字在过程本身生成时显示。如果是这种情况,那么数字可以自行产生,我可以对以前看到的数字实现垃圾收集,从而创建一个无限系列。结果只是在Pi系列之后每秒生成一个数字。这是我通过互联网筛选的结果:这是流行的计算机友好算法,类机器算法:defarccot(x,unity)xpow=unity/xn=1sign=1sum=0loopdoterm=xpow/nbreakifterm==0sum+=sign*(xpow/n)xpow/=x*xn+=2sign=-signendsumenddefcalc_pi(digits