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

Posted

技术标签:

【中文标题】“_from.erb”上的“rails generate scaffold”错误(jbuilder问题?)【英文标题】:"rails generate scaffold" error on "_from.erb" (jbuilder issue?) 【发布时间】:2019-04-06 07:35:38 【问题描述】:

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

宝石文件:

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”部分时似乎有问题。

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

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

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

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

感谢您的宝贵时间!


更新!

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

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

gem 安装 nokogiri

完成此操作后,我心想:“呃,呃,这可能是脚手架问题的解决方案。”确实如此。

【问题讨论】:

你用 foreman 做什么?,你能把它删除,运行 bundle 并重试给你那个错误的命令吗? 有时我在我的开发环境中运行“rails server”而不是“heroku local”。我遇到了一些错误,我认为工头是我试图解决这个问题的遗留问题。无论如何,我删除了它,现在无论以哪种方式运行服务器都没有问题——所以谢谢你。我运行了“gem uninstall foreman”(有多个版本,我按 3 删除所有版本)。我还从我的 gemfile 中删除了它。然后我运行“gem cleanup”,只是为了清理任何剩余的东西。然后我从上面运行“bundle install”和“rails g scaffold..”。不幸的是,我得到了完全相同的错误。 另一个更新。最近还禁用了 turbolinks,它与引导程序混淆,因此弹出窗口不起作用。禁用此功能也无法解决脚手架问题。 【参考方案1】:

详情如上,但是:

嗯,我自己解决了这个问题,只是想报告一下。 所以,我忘记了我在安装 Nokogiri 时也遇到了麻烦。每当我 运行“捆绑更新”我收到一个错误,说我需要做 确保之前正确安装了最新版本的 Nokogiri 继续。我忽略了这一点,因为我无法弄清楚。这 只需按照 nokogiri.org 上的说明解决 安装必要的库:

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

gem install nokogiri

在我这样做之后,我对自己说:“呃,呃,这可能是 解决脚手架问题。”确实如此。

【讨论】:

以上是关于“_from.erb”上的“rails generate scaffold”错误(jbuilder问题?)的主要内容,如果未能解决你的问题,请参考以下文章

同一应用程序上的两种不同语言 PHP 和 Java,Apache 上的 PHP 和 Tomcat 上的 Java

UILabel 上的奇怪行为与 StoryBoard 上的 \n

iPhone 上的字体大小比 PC 上的小

怎么把图片上的字去掉啊?

在 Firefox 中不显示边框,表格上的边框折叠,位置:tbody 上的相对或单元格上的背景颜色

键盘上的PERIOD键在啥地方?