我正试图为我的Rails应用程序创建API。我有下面的控制器。

我有以下的继承
/app/控制器/api/api_Controller.rb
module Api
class ApiController < ApplicationController
# logic/app/控制器/api/home_page_Controller.rb
class Api::HomePageController < Api::ApiController
# logic/app/控制器/api/users_Controller.rb
class Api::UsersController < Api::ApiController
# logic/app/控制器/api/sessions_Controller.rb
class Api::SessionsController < Api::ApiController
# logic/app/控制器/应用程序_控制器。
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
# logic当我试图继承RocketPants::Base时,如pants中所提到的
/app/控制器/api/api_Controller.rb
module Api
class ApiController < RocketPants::Base
skip_before_filter :verify_authenticity_token
protect_from_forgery with: :null_session
# logic我会犯这样的错误
Started POST "/api/sessions" for 104.155.204.133 at 2015-04-21 22:59:56 +0000
ActiveRecord::SchemaMigration Load (0.2ms) SELECT "schema_migrations".* FROM "schema_migrations"
ActionController::RoutingError (undefined method `protect_from_forgery' for Api::ApiController:Class):
app/controllers/api/api_controller.rb:11:in `<class:ApiController>'
app/controllers/api/api_controller.rb:2:in `<module:Api>'
app/controllers/api/api_controller.rb:1:in `<top (required)>'
app/controllers/api/sessions_controller.rb:2:in `<top (required)>'
Rendered /usr/local/rvm/gems/ruby-2.1.4/gems/web-console-2.0.0.beta4/lib/action_dispatch/templates/rescues/_trace.html.erb (3.6ms)
Rendered /usr/local/rvm/gems/ruby-2.1.4/gems/web-console-2.0.0.beta4/lib/action_dispatch/templates/routes/_route.html.erb (40.7ms)
Rendered /usr/local/rvm/gems/ruby-2.1.4/gems/web-console-2.0.0.beta4/lib/action_dispatch/templates/routes/_table.html.erb (19.0ms)
Rendered /usr/local/rvm/gems/ruby-2.1.4/gems/web-console-2.0.0.beta4/lib/action_dispatch/templates/rescues/routing_error.html.erb within rescues/layout (266.2ms)
104.155.204.133 - - [21/Apr/2015:22:59:57 +0000] "POST /api/sessions HTTP/1.1" 404 97164 1.1316我已经添加了gem并执行了包安装。
Gemfile
gem 'rocket_pants', '~> 1.10.0'有人能指点我怎么穿火箭裤吗?
发布于 2015-05-05 22:41:40
从控制器中删除skip_before_filter和protect_from_forgery行。所有的错误都消失了。
https://stackoverflow.com/questions/29785011
复制相似问题