Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8295419
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T14:34:50+00:00 2026-06-08T14:34:50+00:00

I am doing a POST request to my create action in my controller with

  • 0

I am doing a POST request to my create action in my controller with a json like this:

{
  "token":"amsdaashdaksjdh" #assume this is a valid token for a user
  "post": {
     "content":"some random text"
     "title":"random title"
   }
}

However, I have a before_filter check to see if a User is in my database based on the token like this:

before_filter :authenticate


def authenticate
  @user = User.find_by_authentication_token(params[:token])
  if (@user == nil)
    render :json => {error: "invalid token"}
  end
end

It is always giving me the invalid token error…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T14:34:51+00:00Added an answer on June 8, 2026 at 2:34 pm

    A Rails before_filter halts the processing chain when the filter returns nil or false. Because your if statement is the last operation executed, the filter will return nil, when @user is not nil – and this will halt processing.

    You could add an else block returning true when the user has been found.

    def authenticate
      @user = User.find_by_authentication_token(params[:token])
      if @user.nil?
        render :json => {error: "invalid token"}
        false
      else
        true
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im doing a simple ajax request like:` $.ajax({ type: 'POST', url: 'http://' + serverIP
I'm doing a jquery post to an MVC action. The action returns a json
I'm doing a jQuery AJAX post like this: var form = $(#formid); form.submit(function() {
I have an action that looks like this: [Post] [PopulateModelFromId] public ActionResult ChangeName( string
I'm doing user auth via an Ajax post-request in Rails, and I thought that
I am doing a simple $.ajax request: $.ajax({ type: POST, url: /Run/ + param1
I am doing a query that converts rows to columns similar to this post
I need to create an HTTP POST request with parameters. I know there are
I recently made a question based on doing a HTTP request with POST data
I have an action that takes POST data secured by sfGuard. This means that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.