title: undefined method `authenticate_user! Api::PostsController in Devise / Rails 4
body: <p>There is the following routes in my project:</p>
  
  <pre><code>  root 'home#index'
  
    namespace :api, defaults: { format: :json } do
      devise_for :users, controllers: { sessions: "api/sessions" }
      resources :posts
    end
  </code></pre>
  
  <p>User model:</p>
  
  <pre><code>class User &lt; ActiveRecord::Base
      has_many :posts,        dependent: :destroy
      has_many :comments, dependent: :destroy
  
      validates :name, presence: true
  
      devise :database_authenticatable, :rememberable
  end
  </code></pre>
  
  <p>Session controller:</p>
  
  <pre><code>class Api::SessionsController &lt; Devise::SessionsController
    def create
      @user = User.find_for_database_authentication(email: params[:user][:email])
      if @user &amp;&amp; @user.valid_password?(params[:user][:password])
          sign_in(@user)
      else
          warden.custom_failure!
        @errors = [ 'Invalid email or password' ]
          render 'api/shared/errors', status: :unauthorized
      end
      end
  end
  </code></pre>
  
  <p>Application controller:</p>
  
  <pre><code>class ApplicationController &lt; 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
  </code></pre>
  
  <p>At last my Post controller:</p>
  
  <pre><code>class Api::PostsController &lt; ApplicationController
      before_action :authenticate_user!, only: [ :create ]
  
      def create
        current_user.posts.create!(post_params)
      end
  
      private
  
          def post_params
              params.require(:post).permit(:title, :content)
          end
  end
  </code></pre>
  
  <p>But when I try to create a new Post I get the following error: "undefined method `authenticate_user! Api::PostsController". If I delete it, I get the error about 'current_user' method. What's the trouble? How can I fix it? Thanks in advance!!!</p>