module Api
class ApiController < RocketPants::Base
skip_before_filter :verify_authenticity_token
protect_from_forgery with: :null_session
# logic
I get (undefined method `protect_from_forgery' for Api::ApiController:Class)error like this
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"
Since we don't use the full rails stack, you can remove the skip_before_filter and protect_from_forgery lines from your controller, as we don't support them.
I am trying to create API for my Rails app. I have these following controllers.
I have the following inheritance
/app/controllers/api/api_controller.rb
/app/controllers/api/home_page_controller.rb
/app/controllers/api/users_controller.rb
/app/controllers/api/sessions_controller.rb
/app/controllers/application_controller.rb
When I try to inherit from RocketPants::Base like the following as mentioned in https://github.com/Sutto/rocket_pants
/app/controllers/api/api_controller.rb
I get (undefined method `protect_from_forgery' for Api::ApiController:Class)error like this
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 I have added the gem and executed bundle install.
Gemfile
Can someone kindly guide me how to add rocketpants?