"rails generate scaffold" 关于“_from.erb”的错误(jbuilder 问题?)

"rails generate scaffold" error on "_from.erb" (jbuilder issue?)

我对 Ruby 和 Rails 比较陌生,一直在空闲时间自学。我最近在我的 gemfile 中添加了一些 gem,现在我的脚手架给我错误——在 Whosebug 上找不到另一个解决我问题的答案(如果我的搜索能力没有达到标准,请提前道歉)。

宝石文件:

source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '2.5.1'

# Set up local .env file, require immediately
gem 'dotenv-rails', :require => 'dotenv/rails-now'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.2.1'

# Use postgresql as the database for Active Record
gem 'pg'
# 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 'duktape'
# 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'

# 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'
  # Mailcatcher for local mail debugging
  gem 'mailcatcher'
end

group :test do
  # Adds support for Capybara system testing and selenium driver
  gem 'capybara', '>= 2.15', '< 4.0'
  gem 'selenium-webdriver'
  # Easy installation and use of chromedriver to run system tests with Chrome
  gem 'chromedriver-helper'
end

# group :development, :test do
#   gem 'foreman'
# end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

#Add Sprockets for installing gems
gem 'sprockets-rails', '>= 2.3.2', :require => 'sprockets/railtie'

#Add Bootstrap
gem 'bootstrap', '>= 4.1.3'

#Add JQuery (for Bootstrap)
gem 'jquery-rails', '~> 4.3.1'

#Add Chart.js for analytics
gem 'chart-js-rails', '~> 0.1.6' 

#Add Devise for Authorization and Authentication
gem 'devise', '~> 4.4.3'

#Add Font Awesome Icons
gem 'font-awesome-sass', '~> 5.2.0'

#Mini-Magick for Image Processing (のし Generator)
gem 'mini_magick'

#Auto-upload setup for AWS S3
gem 'carrierwave'
gem 'carrierwave-google-storage'

# Easy Categories for Manual Articles
gem 'ancestry'

# CKEditor WYSIWYG text editor
gem 'simple_form'
gem 'ckeditor', github: 'galetahub/ckeditor'

# Sendgrid for confirmations, etc.
gem 'sendgrid-ruby'

这是我尝试生成脚手架时的错误:

rails generate scaffold Market namae:string address:string phone:string repphone:string fax:string cost:decimal excost:decimal history:string
      invoke  active_record
   identical    db/migrate/20181029224847_create_markets.rb
   identical    app/models/market.rb
      invoke    test_unit
   identical      test/models/market_test.rb
   identical      test/fixtures/markets.yml
      invoke  resource_route
       route    resources :markets
      invoke  scaffold_controller
   identical    app/controllers/markets_controller.rb
      invoke    erb
       exist      app/views/markets
    conflict      app/views/markets/index.html.erb
    Overwrite /home/mudl/kanri/Dropbox/funabiki-online-h/app/views/markets/index.html.erb? (enter "h" for help) [Ynaqdh] n
        skip      app/views/markets/index.html.erb
   identical      app/views/markets/edit.html.erb
   identical      app/views/markets/show.html.erb
    conflict      app/views/markets/new.html.erb
    Overwrite /home/mudl/kanri/Dropbox/funabiki-online-h/app/views/markets/new.html.erb? (enter "h" for help) [Ynaqdh] n
        skip      app/views/markets/new.html.erb
Traceback (most recent call last):
    71: from bin/rails:4:in `<main>'
    70: from /home/mudl/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activesupport-5.2.1/lib/active_support/dependencies.rb:287:in `require'
    69: from /home/mudl/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activesupport-5.2.1/lib/active_support/dependencies.rb:253:in `load_dependency'
    68: from /home/mudl/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activesupport-5.2.1/lib/active_support/dependencies.rb:287:in `block in require'
    67: from /home/mudl/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:29:in `require'
    66: from /home/mudl/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:20:in `require_with_bootsnap_lfi'
    65: from /home/mudl/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/loaded_features_index.rb:65:in `register'
    64: from /home/mudl/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `block in require_with_bootsnap_lfi'
    63: from /home/mudl/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require'
    62: from /home/mudl/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/railties-5.2.1/lib/rails/commands.rb:18:in `<main>'
    61: from /home/mudl/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/railties-5.2.1/lib/rails/command.rb:46:in `invoke'
    60: from /home/mudl/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/railties-5.2.1/lib/rails/command/base.rb:65:in `perform'
    59: from /home/mudl/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/thor-0.19.4/lib/thor.rb:369:in `dispatch'
    58: from /home/mudl/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/thor-0.19.4/lib/thor/invocation.rb:126:in `invoke_command'
    57: from /home/mudl/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/thor-0.19.4/lib/thor/command.rb:27:in `run'
    56: from /home/mudl/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/railties-5.2.1/lib/rails/commands/generate/generate_command.rb:26:in `perform'
    55: from /home/mudl/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/railties-5.2.1/lib/rails/generators.rb:276:in `invoke'
    54: from /home/mudl/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/thor-0.19.4/lib/thor/base.rb:444:in `start'
    53: from /home/mudl/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/thor-0.19.4/lib/thor/group.rb:232:in `dispatch'
    52: from /home/mudl/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/thor-0.19.4/lib/thor/invocation.rb:133:in `invoke_all'
    51: from /home/mudl/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/thor-0.19.4/lib/thor/invocation.rb:133:in `map'
    50: from /home/mudl/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/thor-0.19.4/lib/thor/invocation.rb:133:in `each'
    49: from /home/mudl/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/thor-0.19.4/lib/thor/invocation.rb:133:in `block in invoke_all'
    48: from /home/mudl/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/thor-0.19.4/lib/thor/invocation.rb:126:in `invoke_command'
    47: from /home/mudl/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/thor-0.19.4/lib/thor/command.rb:27:in `run'
    46: from /home/mudl/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/thor-0.19.4/lib/thor/group.rb:133:in `_invoke_from_option_scaffold_controller'
    45: from /home/mudl/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/thor-0.19.4/lib/thor/group.rb:266:in `_invoke_for_class_method'
    44: from /home/mudl/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/thor-0.19.4/lib/thor/shell.rb:68:in `with_padding'
    43: from /home/mudl/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/thor-0.19.4/lib/thor/group.rb:277:in `block in _invoke_for_class_method'
    42: from /home/mudl/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/thor-0.19.4/lib/thor/invocation.rb:115:in `invoke'
    41: from /home/mudl/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/thor-0.19.4/lib/thor/group.rb:232:in `dispatch'
    40: from /home/mudl/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/thor-0.19.4/lib/thor/invocation.rb:133:in `invoke_all'
    39: from /home/mudl/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/thor-0.19.4/lib/thor/invocation.rb:133:in `map'
    38: from /home/mudl/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/thor-0.19.4/lib/thor/invocation.rb:133:in `each'
    37: from /home/mudl/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/thor-0.19.4/lib/thor/invocation.rb:133:in `block in invoke_all'
    36: from /home/mudl/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/thor-0.19.4/lib/thor/invocation.rb:126:in `invoke_command'
    35: from /home/mudl/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/thor-0.19.4/lib/thor/command.rb:27:in `run'
    34: from /home/mudl/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/thor-0.19.4/lib/thor/group.rb:133:in `_invoke_from_option_template_engine'
    33: from /home/mudl/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/thor-0.19.4/lib/thor/group.rb:266:in `_invoke_for_class_method'
    32: from /home/mudl/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/thor-0.19.4/lib/thor/shell.rb:68:in `with_padding'
    31: from /home/mudl/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/thor-0.19.4/lib/thor/group.rb:274:in `block in _invoke_for_class_method'
    30: from /home/mudl/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/thor-0.19.4/lib/thor/group.rb:274:in `instance_exec'
    29: from /home/mudl/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/railties-5.2.1/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb:26:in `block in <class:ScaffoldControllerGenerator>'
    28: from /home/mudl/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/thor-0.19.4/lib/thor/invocation.rb:115:in `invoke'
    27: from /home/mudl/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/thor-0.19.4/lib/thor/group.rb:232:in `dispatch'
    26: from /home/mudl/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/thor-0.19.4/lib/thor/invocation.rb:133:in `invoke_all'
    25: from /home/mudl/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/thor-0.19.4/lib/thor/invocation.rb:133:in `map'
    24: from /home/mudl/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/thor-0.19.4/lib/thor/invocation.rb:133:in `each'
    23: from /home/mudl/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/thor-0.19.4/lib/thor/invocation.rb:133:in `block in invoke_all'
    22: from /home/mudl/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/thor-0.19.4/lib/thor/invocation.rb:126:in `invoke_command'
    21: from /home/mudl/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/thor-0.19.4/lib/thor/command.rb:27:in `run'
    20: from /home/mudl/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/railties-5.2.1/lib/rails/generators/erb/scaffold/scaffold_generator.rb:18:in `copy_view_files'
    19: from /home/mudl/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/railties-5.2.1/lib/rails/generators/erb/scaffold/scaffold_generator.rb:18:in `each'
    18: from /home/mudl/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/railties-5.2.1/lib/rails/generators/erb/scaffold/scaffold_generator.rb:19:in `block in copy_view_files'
    17: from /home/mudl/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/railties-5.2.1/lib/rails/generators/erb/scaffold/scaffold_generator.rb:19:in `each'
    16: from /home/mudl/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/railties-5.2.1/lib/rails/generators/erb/scaffold/scaffold_generator.rb:21:in `block (2 levels) in copy_view_files'
    15: from /home/mudl/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/railties-5.2.1/lib/rails/generators/named_base.rb:24:in `template'
    14: from /home/mudl/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/railties-5.2.1/lib/rails/generators/named_base.rb:49:in `inside_template'
    13: from /home/mudl/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/railties-5.2.1/lib/rails/generators/named_base.rb:25:in `block in template'
    12: from /home/mudl/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/thor-0.19.4/lib/thor/actions/file_manipulation.rb:115:in `template'
    11: from /home/mudl/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/thor-0.19.4/lib/thor/actions/create_file.rb:25:in `create_file'
    10: from /home/mudl/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/thor-0.19.4/lib/thor/actions.rb:95:in `action'
     9: from /home/mudl/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/thor-0.19.4/lib/thor/actions/create_file.rb:60:in `invoke!'
     8: from /home/mudl/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/thor-0.19.4/lib/thor/actions/empty_directory.rb:113:in `invoke_with_conflict_check'
     7: from /home/mudl/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/thor-0.19.4/lib/thor/actions/create_file.rb:72:in `on_conflict_behavior'
     6: from /home/mudl/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/thor-0.19.4/lib/thor/actions/create_file.rb:46:in `identical?'
     5: from /home/mudl/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/thor-0.19.4/lib/thor/actions/create_file.rb:53:in `render'
     4: from /home/mudl/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/thor-0.19.4/lib/thor/actions/file_manipulation.rb:116:in `block in template'
     3: from /home/mudl/.rbenv/versions/2.5.1/lib/ruby/2.5.0/erb.rb:876:in `result'
     2: from /home/mudl/.rbenv/versions/2.5.1/lib/ruby/2.5.0/erb.rb:876:in `eval'
     1: from (erb):2:in `template'
(erb):2:in `concat': can't modify frozen String (FrozenError)

如您所见,当它到达脚手架生成的“_form.html”部分时似乎出现了问题。

我检查以确保文件没有 st运行ge 权限。我怀疑它与 Foreman(这是 Heroku 的东西)或 dotenv(这是本地开发所必需的,所以我可以存储秘密)有关。我在其他地方发现了一些关于 rails 5.1 的先前 beta 版本与 Thor 有问题的帖子,但我什至不知道 Thor 做了什么(这是某种依赖),他们说该错误已在后续版本中修复(例如反正我用的是 5.2)。

我的另一个理论是它与 Jbuilder 和 json 东西有关,我也是新手,甚至不知道从哪里开始解决。

有什么想法吗?与此同时,我将在没有脚手架的情况下工作。

无论如何,感谢您的宝贵时间!

感谢您的宝贵时间!


更新!

好吧,我自己解决了这个问题,只是想反馈一下。所以,我忘记了我在安装 Nokogiri 时也遇到了麻烦。每当我 运行 “bundle update”时,我都会收到一个错误,提示我需要确保在继续之前正确安装了最新版本的 Nokogiri。我忽略了这一点,因为我无法弄清楚。只需按照 nokogiri.org 中的说明并安装必要的库即可解决此问题:

sudo apt-get install build-essential patch ruby-dev zlib1g-dev liblzma-dev

gem install nokogiri

在我这样做之后,我心想“呃,呃,这可能是脚手架问题的解决方案。”确实是。

上面的详细信息,但是:

Well, I solved the problem on my own, and just wanted to report back. So, I forgot I had had trouble installing Nokogiri as well. Whenever I ran "bundle update" I was getting an error that said I needed to make sure the latest version of Nokogiri was installed correctly before continuing. I ignored this, because I couldn't figure out out. This was solved by simply following the instructions at nokogiri.org and installing the necessary libraries:

sudo apt-get install build-essential patch ruby-dev zlib1g-dev liblzma-dev

gem install nokogiri

After I did this I thought to myself "Uh, duh, this is probably the solution to the scaffolding issue." Indeed it was.