Spree 前端助手不可用,导致 "undefined local variable or method `body_class'"
Spree frontend helpers not available, leading to"undefined local variable or method `body_class'"
我正在尝试在现有应用程序上安装 Spree。它安装成功,但是当导航到任何 Spree 页面时,我在第 10 行 spree_frontend-3.0.4/app/views/spree/layouts/spree_application.html.erb
中收到 "undefined local variable or method 'body_class'"
错误。
body_class
是 spree_frontend-3.0.4/app/helpers/spree/frontend_helper.rb
中的一个方法,因此该文件中的辅助方法似乎不可用。但为什么不呢?
我尝试设置一个全新的 Rails 应用程序并在其上安装 Spree,它成功了。所以我现有的应用程序有一些奇怪的东西干扰了 Spree,但我想不出它可能是什么。
这是我的 Gemfile,以防有帮助:
source 'https://rubygems.org'
ruby '2.2.0'
gem 'rails', '4.2.3'
gem 'sass-rails', "~> 4.0.2"
gem 'celluloid', '~> 0.16.0'
gem 'unicorn'
gem 'bootstrap-sass', '~> 3.3.5'
gem 'bcrypt-ruby', '3.1.2'
#gem 'faker', '1.1.2'
gem 'kaminari'
gem 'kaminari-bootstrap', '~> 3.0.1'
gem 'pg'
gem 'devise', '>= 3.5.1'
gem "devise-async"
gem 'dependent-fields-rails'
gem 'underscore-rails'
gem "marco-polo"
gem 'aws-sdk', '~> 1.63'
gem 'aws-sdk-resources', '~> 2'
gem 'paperclip', "~> 4.1"
gem 'delayed_job_active_record'
gem 'delayed_job_web'
# gem 'hirefire', :github => 'michaelkeenan/hirefire'
gem 's3_direct_upload', :github => 'maxgillett/s3_direct_upload'
# gem 's3_multipart', :github => 'maxgillett/s3_multipart'
#gem "s3_multipart", :path => "../s3_multipart"
gem "s3_multipart", :github => 'michaelkeenan/s3_multipart', :tag => 'v0.0.11.9'
#gem 'rest_in_place', :git => "git://github.com/michaelkeenan/rest_in_place.git"
gem 'best_in_place', '~> 3.0.1'
gem 'pundit'
gem 'data-confirm-modal', github: 'ifad/data-confirm-modal'
gem 'money-rails'
gem 'font-awesome-sass'
# gem 'jquery-turbolinks'
gem 'rubyzip', '~> 1.1.6', require: 'zip'
gem 'obfuscate_id', '~> 0.0.5', :git => "git://github.com/michaelkeenan/obfuscate_id.git"
gem 'redcarpet'
gem 'pagedown-bootstrap-rails'
gem 'honeybadger'
gem "paranoia"
gem 'paranoia_uniqueness_validator', '1.1.0'
gem 'unscoped_associations'
gem 'friendly_id', '~> 5.1.0'
gem 'nokogiri'
gem "hirefire-resource"
gem 'acts_as_list'
gem 'mailboxer', '~> 0.13.0'
gem 'zeroclipboard-rails'
gem 'bootstrap-datepicker-rails'
gem "awesome_print", require:"ap"
gem 'cloudfront-signer'
gem 'rack-attack'
group :development do
gem 'better_errors'
gem 'binding_of_caller', :platforms=>[:mri_19, :mri_20, :rbx]
gem 'rails_layout'
gem 'bullet'
gem 'did_you_mean', '~> 0.9.5'
gem 'quiet_assets'
gem 'meta_request'
gem 'pry-rails'
end
group :development, :test do
gem 'spring', '~> 1.3.6'
gem "spring-commands-rspec"
gem 'minitest'
gem 'rspec-rails', '~> 3.2'
gem 'guard-rspec'
gem 'rb-fsevent', :require => false
#gem 'guard-zeus'
gem 'growl', '1.0.3'
gem 'childprocess', '0.5.0'
gem 'email_spec'
gem 'pry-byebug'
gem 'pry-stack_explorer'
gem 'pry-remote'
end
group :test do
gem 'selenium-webdriver', '2.41.0'
gem 'capybara'
gem 'capybara-webkit'
gem 'factory_girl_rails', '4.2.1', :require => false
gem 'database_cleaner'
end
#group :assets do
gem 'sprockets-rails', :require => 'sprockets/railtie'
gem 'coffee-rails', '~> 4.0.0'
gem 'uglifier', '>= 1.3.0'
gem "fog", "~>1.28"
gem 'asset_sync'
#end
gem 'jquery-rails', '4.0.4'
gem 'jquery-ui-rails', '5.0.5'
gem 'remotipart', '~> 1.2'
# gem 'turbolinks'
gem 'jbuilder', '~> 1.2'
group :doc do
gem 'sdoc', '0.3.20', require: false
end
group :production do
gem 'rails_12factor', '0.0.2'
gem 'lograge'
end
gem 'spree', '3.0.4'
这原来是由于 s3_multipart gem,或者更确切地说,是由于它生成的文件。它从 ApplicationController:
创建一个 class subclassed
class ItemUploader < ApplicationController
...
end
由于 action_controller/railties/helpers.rb
中的条件,这会破坏辅助方法:
if klass.superclass == ActionController::Base && ActionController::Base.
klass.helper :all
end
Someone else reported it here.
要解决它,请将 ItemUploader 从 ActionController::Base
更改为 subclass。 s3_multipart 仍然适用于此更改,并且不会破坏辅助方法。
class ItemUploader < ActionController::Base
...
end
我正在尝试在现有应用程序上安装 Spree。它安装成功,但是当导航到任何 Spree 页面时,我在第 10 行 spree_frontend-3.0.4/app/views/spree/layouts/spree_application.html.erb
中收到 "undefined local variable or method 'body_class'"
错误。
body_class
是 spree_frontend-3.0.4/app/helpers/spree/frontend_helper.rb
中的一个方法,因此该文件中的辅助方法似乎不可用。但为什么不呢?
我尝试设置一个全新的 Rails 应用程序并在其上安装 Spree,它成功了。所以我现有的应用程序有一些奇怪的东西干扰了 Spree,但我想不出它可能是什么。
这是我的 Gemfile,以防有帮助:
source 'https://rubygems.org'
ruby '2.2.0'
gem 'rails', '4.2.3'
gem 'sass-rails', "~> 4.0.2"
gem 'celluloid', '~> 0.16.0'
gem 'unicorn'
gem 'bootstrap-sass', '~> 3.3.5'
gem 'bcrypt-ruby', '3.1.2'
#gem 'faker', '1.1.2'
gem 'kaminari'
gem 'kaminari-bootstrap', '~> 3.0.1'
gem 'pg'
gem 'devise', '>= 3.5.1'
gem "devise-async"
gem 'dependent-fields-rails'
gem 'underscore-rails'
gem "marco-polo"
gem 'aws-sdk', '~> 1.63'
gem 'aws-sdk-resources', '~> 2'
gem 'paperclip', "~> 4.1"
gem 'delayed_job_active_record'
gem 'delayed_job_web'
# gem 'hirefire', :github => 'michaelkeenan/hirefire'
gem 's3_direct_upload', :github => 'maxgillett/s3_direct_upload'
# gem 's3_multipart', :github => 'maxgillett/s3_multipart'
#gem "s3_multipart", :path => "../s3_multipart"
gem "s3_multipart", :github => 'michaelkeenan/s3_multipart', :tag => 'v0.0.11.9'
#gem 'rest_in_place', :git => "git://github.com/michaelkeenan/rest_in_place.git"
gem 'best_in_place', '~> 3.0.1'
gem 'pundit'
gem 'data-confirm-modal', github: 'ifad/data-confirm-modal'
gem 'money-rails'
gem 'font-awesome-sass'
# gem 'jquery-turbolinks'
gem 'rubyzip', '~> 1.1.6', require: 'zip'
gem 'obfuscate_id', '~> 0.0.5', :git => "git://github.com/michaelkeenan/obfuscate_id.git"
gem 'redcarpet'
gem 'pagedown-bootstrap-rails'
gem 'honeybadger'
gem "paranoia"
gem 'paranoia_uniqueness_validator', '1.1.0'
gem 'unscoped_associations'
gem 'friendly_id', '~> 5.1.0'
gem 'nokogiri'
gem "hirefire-resource"
gem 'acts_as_list'
gem 'mailboxer', '~> 0.13.0'
gem 'zeroclipboard-rails'
gem 'bootstrap-datepicker-rails'
gem "awesome_print", require:"ap"
gem 'cloudfront-signer'
gem 'rack-attack'
group :development do
gem 'better_errors'
gem 'binding_of_caller', :platforms=>[:mri_19, :mri_20, :rbx]
gem 'rails_layout'
gem 'bullet'
gem 'did_you_mean', '~> 0.9.5'
gem 'quiet_assets'
gem 'meta_request'
gem 'pry-rails'
end
group :development, :test do
gem 'spring', '~> 1.3.6'
gem "spring-commands-rspec"
gem 'minitest'
gem 'rspec-rails', '~> 3.2'
gem 'guard-rspec'
gem 'rb-fsevent', :require => false
#gem 'guard-zeus'
gem 'growl', '1.0.3'
gem 'childprocess', '0.5.0'
gem 'email_spec'
gem 'pry-byebug'
gem 'pry-stack_explorer'
gem 'pry-remote'
end
group :test do
gem 'selenium-webdriver', '2.41.0'
gem 'capybara'
gem 'capybara-webkit'
gem 'factory_girl_rails', '4.2.1', :require => false
gem 'database_cleaner'
end
#group :assets do
gem 'sprockets-rails', :require => 'sprockets/railtie'
gem 'coffee-rails', '~> 4.0.0'
gem 'uglifier', '>= 1.3.0'
gem "fog", "~>1.28"
gem 'asset_sync'
#end
gem 'jquery-rails', '4.0.4'
gem 'jquery-ui-rails', '5.0.5'
gem 'remotipart', '~> 1.2'
# gem 'turbolinks'
gem 'jbuilder', '~> 1.2'
group :doc do
gem 'sdoc', '0.3.20', require: false
end
group :production do
gem 'rails_12factor', '0.0.2'
gem 'lograge'
end
gem 'spree', '3.0.4'
这原来是由于 s3_multipart gem,或者更确切地说,是由于它生成的文件。它从 ApplicationController:
创建一个 class subclassedclass ItemUploader < ApplicationController
...
end
由于 action_controller/railties/helpers.rb
中的条件,这会破坏辅助方法:
if klass.superclass == ActionController::Base && ActionController::Base.
klass.helper :all
end
Someone else reported it here.
要解决它,请将 ItemUploader 从 ActionController::Base
更改为 subclass。 s3_multipart 仍然适用于此更改,并且不会破坏辅助方法。
class ItemUploader < ActionController::Base
...
end