Ruby on Rails + Psych::DisallowedClass in PostsController#show

huangapple go评论62阅读模式
英文:

Ruby on Rails + Psych::DisallowedClass in PostsController#show

问题

以下是Gemfile中的部分内容的翻译:

source 'https://rubygems.org'

ruby '2.7.1'

git_source(:github) do |repo_name|
  repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
  "https://github.com/#{repo_name}.git"
end

# 我安装的 gems
gem 'aws-sdk-s3'
gem 'bootsnap', require: false
gem 'simple_form'
gem 'friendly_id', '~> 5.1.0'
gem 'devise'
gem 'will_paginate', '~> 3.1.0'
gem 'meta-tags'
gem 'omniauth'
gem "omniauth-rails_csrf_protection", "~> 1.0"
gem 'omniauth-twitter'
gem 'impressionist', '~>1.6.1'
gem 'gibbon'
gem 'acts_as_votable', '~> 0.11.1'
gem 'awesome_print'
gem 'sanitize'
gem "mini_magick"
gem "redcarpet"
gem 'file_validators'
gem 'pg_search'
gem 'invisible_captcha'
gem "recaptcha"

# 使用 edge Rails 替代:gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.2'
# 使用 sqlite3 作为 Active Record 的数据库
gem 'pg'
# 使用 Puma 作为应用服务器
gem 'puma', '~> 3.7'
# 使用 SCSS 作为样式表
gem 'sass-rails', '~> 5.0'
# 使用 Uglifier 作为 JavaScript 资源的压缩器
gem 'uglifier', '>= 1.3.0'
# 有关更多支持的运行时,请参见 https://github.com/rails/execjs#readme
# gem 'therubyracer', platforms: :ruby

# 使用 CoffeeScript 处理 .coffee 资源和视图
gem 'coffee-rails', '~> 4.2'
# Turbolinks 让你的 Web 应用程序导航更快。了解更多:https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# 使用 Jbuilder 构建 JSON API
gem 'jbuilder', '~> 2.5'
# 在生产中使用 Redis 适配器运行 Action Cable
# gem 'redis', '~> 3.0'
# 使用 ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# 使用 Capistrano 进行部署
# gem 'capistrano-rails', group: :development

group :development, :test do
  # 在代码中的任何位置调用 'byebug' 都可以停止执行并获取调试器控制台
  gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
  # 添加对 Capybara 系统测试和 selenium 驱动程序的支持
  gem 'capybara', '~> 2.13'
  gem 'selenium-webdriver'
end

group :development do
  # 在异常页面上或在代码中的任何位置使用 '<%= console %>' 来访问 IRB 控制台
  gem 'web-console', '>= 3.3.0'
  gem 'listen', '>= 3.0.5', '< 3.2'
  # Spring 通过在后台运行应用程序来加速开发。了解更多:https://github.com/rails/spring
  gem 'spring'
  gem 'spring-watcher-listen', '~> 2.0.0'
end

# Windows 不包括 zoneinfo 文件,因此请捆绑 tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

gem 'mina'
gem 'elasticsearch-model'
gem 'elasticsearch-rails'

请注意,翻译中保留了Gemfile中的代码和注释,并仅对注释进行了翻译。

英文:

Never seen this error before. I wonder if it is about the RoR env setup than my codes.

btw why is it even "klassname", should it not be with c "classname"

Ruby on Rails + Psych::DisallowedClass in PostsController#show


My Gemfile

source &#39;https://rubygems.org&#39;
ruby &#39;2.7.1&#39;
git_source(:github) do |repo_name|
repo_name = &quot;#{repo_name}/#{repo_name}&quot; unless repo_name.include?(&quot;/&quot;)
&quot;https://github.com/#{repo_name}.git&quot;
end
# gems I installed
gem &#39;aws-sdk-s3&#39;
gem &#39;bootsnap&#39;, require: false
gem &#39;simple_form&#39;
gem &#39;friendly_id&#39;, &#39;~&gt; 5.1.0&#39;
gem &#39;devise&#39;
gem &#39;will_paginate&#39;, &#39;~&gt; 3.1.0&#39;
gem &#39;meta-tags&#39;
gem &#39;omniauth&#39;
gem &quot;omniauth-rails_csrf_protection&quot;, &quot;~&gt; 1.0&quot;
gem &#39;omniauth-twitter&#39;
gem &#39;impressionist&#39;, &#39;~&gt;1.6.1&#39;
gem &#39;gibbon&#39;
gem &#39;acts_as_votable&#39;, &#39;~&gt; 0.11.1&#39;
gem &#39;awesome_print&#39;
gem &#39;sanitize&#39;
gem &quot;mini_magick&quot;
gem &quot;redcarpet&quot;
gem &#39;file_validators&#39;
gem &#39;pg_search&#39;
gem &#39;invisible_captcha&#39;
gem &quot;recaptcha&quot;
# Bundle edge Rails instead: gem &#39;rails&#39;, github: &#39;rails/rails&#39;
gem &#39;rails&#39;, &#39;~&gt; 5.2&#39;
# Use sqlite3 as the database for Active Record
gem &#39;pg&#39;
# Use Puma as the app server
gem &#39;puma&#39;, &#39;~&gt; 3.7&#39;
# Use SCSS for stylesheets
gem &#39;sass-rails&#39;, &#39;~&gt; 5.0&#39;
# Use Uglifier as compressor for JavaScript assets
gem &#39;uglifier&#39;, &#39;&gt;= 1.3.0&#39;
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem &#39;therubyracer&#39;, platforms: :ruby
# Use CoffeeScript for .coffee assets and views
gem &#39;coffee-rails&#39;, &#39;~&gt; 4.2&#39;
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem &#39;turbolinks&#39;, &#39;~&gt; 5&#39;
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem &#39;jbuilder&#39;, &#39;~&gt; 2.5&#39;
# Use Redis adapter to run Action Cable in production
# gem &#39;redis&#39;, &#39;~&gt; 3.0&#39;
# Use ActiveModel has_secure_password
# gem &#39;bcrypt&#39;, &#39;~&gt; 3.1.7&#39;
# Use Capistrano for deployment
# gem &#39;capistrano-rails&#39;, group: :development
group :development, :test do
# Call &#39;byebug&#39; anywhere in the code to stop execution and get a debugger console
gem &#39;byebug&#39;, platforms: [:mri, :mingw, :x64_mingw]
# Adds support for Capybara system testing and selenium driver
gem &#39;capybara&#39;, &#39;~&gt; 2.13&#39;
gem &#39;selenium-webdriver&#39;
end
group :development do
# Access an IRB console on exception pages or by using &lt;%= console %&gt; anywhere in the code.
gem &#39;web-console&#39;, &#39;&gt;= 3.3.0&#39;
gem &#39;listen&#39;, &#39;&gt;= 3.0.5&#39;, &#39;&lt; 3.2&#39;
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem &#39;spring&#39;
gem &#39;spring-watcher-listen&#39;, &#39;~&gt; 2.0.0&#39;
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem &#39;tzinfo-data&#39;, platforms: [:mingw, :mswin, :x64_mingw, :jruby]
gem &#39;mina&#39;
gem &#39;elasticsearch-model&#39;
gem &#39;elasticsearch-rails&#39;

答案1

得分: 1

我认为问题出在Psych gem版本上。

你可以尝试在application.rb中添加这一行:

config.active_record.yaml_column_permitted_classes = [Symbol, Hash, Array, ActiveSupport::HashWithIndifferentAccess]
英文:

I think the issue is with Psych gem version.

You can try adding this line application.rb

config.active_record.yaml_column_permitted_classes = [Symbol, Hash, Array, ActiveSupport::HashWithIndifferentAccess]

huangapple
  • 本文由 发表于 2023年6月12日 15:28:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/76454420.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定