gpt4 book ai didi

ruby-on-rails - ApplicationController :Class 的路由错误未定义局部变量或方法 `with'

转载 作者:行者123 更新时间:2023-12-04 06:36:25 26 4
gpt4 key购买 nike

我是 Rails 的新手,我不明白为什么会出现此错误:

undefined local variable or method `with' for ApplicationController:Class

路由:

root 'home#index'

Controller :

class HomeController < ApplicationController

def new
end

def index
end

end

应用跟踪:

app/controllers/application_controller.rb:4:in `<class:ApplicationController>'
app/controllers/application_controller.rb:1:in `<top (required)>'
app/controllers/home_controller.rb:1:in `<top (required)>'

我已经更新了一些模型和 rspec 代码来测试模型验证,但除此之外我没有创建其他 Controller / View /路由等。

注意:ruby 2.0.0,rails 4.0.0

应用程序 Controller :

class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with::exception
end

也许这是一些吓坏了的 gem ?

gem 文件:

source 'https://rubygems.org'
ruby '2.0.0'


# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby


gem 'rails', '4.0.0'

group :development do
gem 'sqlite3', '1.3.7'
gem 'rspec-rails', '2.14.0'
gem 'guard-rspec', '3.0.2'
gem 'guard-spork', '1.5.1'
gem 'factory_girl', '4.2.0'
gem 'factory_girl_rails', '4.2.1'
end
gem 'mysql', '2.9.1'
gem 'mysql2', '0.3.13'

gem 'sass-rails', '4.0.0'
gem 'uglifier', '2.1.1'
gem 'coffee-rails', '4.0.0'
gem 'jquery-rails', '2.2.1'
gem 'turbolinks', '1.1.1'
gem 'jbuilder', '1.2'


group :test do
gem 'email_spec', '1.5.0'
#gem 'selenium-webdriver', '2.0.0'
#gem 'capybara', '2.1.0'
end

group :doc do
gem 'sdoc', '0.3.20', require: false
end

最佳答案

看起来你需要在第 4 行有一个空格。

所以

protect_from_forgery with::exception

变成:

protect_from_forgery with: :exception

原因是 protect_from_forgery 是一种将散列作为其唯一参数的方法。

关于ruby-on-rails - ApplicationController :Class 的路由错误未定义局部变量或方法 `with',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18708529/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com