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 273545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T00:28:21+00:00 2026-05-12T00:28:21+00:00

Okay so from what I’ve read on other websites and on stack overflow, Rails

  • 0

Okay so from what I’ve read on other websites and on stack overflow, Rails throws this Authentication token error because my form doesn’t pass the token — and it’s a security feature. This I understand.

However I don’t really have a form. I have ajax here — my javascript posts the id’ed information into a processing function.

So my question is, how do I get the authentication token to my controller?

My view looks like this:

<% for transaction in @transactions %>
        <% if transaction["category"] == '' %>
        <% transaction["category"] = "Uncategorized" %>
                        <% end %>

                        <tr title = "<% if params[:type] %><%= params[:type] %><% else %>Purchases<% end %> <%= transaction["id"] %>" >

                            <td class="check"><a class="help" href="#"><img src="/images/icons/help.png" alt="?" /></a><input type="checkbox" /></td>
                            <td class="date"><% if transaction["date"] != "0000-00-00 00:00:00" %><%= transaction["date"].to_date.strftime("%B %d") %><% end %></td>

                            <% if params[:type] == "Bills" || params[:type] == "Reimbursements" %>
                            <td class="payee"><%= transaction["payee"] %></td>
                            <td class="details"><%= transaction["details"] %></td>
                            <% else %>
                            <td class="description"><% if transaction["detail"] == "undefined" %>n/a<% else %><%= transaction["detail"] %><% end %></td>
                            <td class="category">n/a</td>
                            <% end %>

                            <td class="amount">-$<%= transaction["amount"] %></td>
                        </tr>

                    <% end %>

The corresponding ajax is as follows:

/* send ids by ajax */
$('#tableActions li a').click(function() { 
    if(!$(this).hasClass('disabled')) {
        action = $(this).text();
        ids = new Array();
        i = 0;
        $('td.check input','#tableHolder').each(function() { if($(this).attr('checked')) { ids[i++] = $(this).parents('tr').attr('title'); } });
        $.ajax({
            type: "POST",
            url: "/bulkaction",
            data: "=" + action + "&ids=" + ids + "&authenticity_token=" + encodeURIComponent(AUTH_TOKEN),
            success: function(data){
                $('#tableHolder').html(data);
                /* bring back all functionality */
                initTable();
                /* set default sorting by date desc */
                $('th').removeClass('sortUp sortDown');
                $('th:eq(1)').addClass('sortDown'); 
                /* disable all actions */
                $('#tableActions li a').addClass('disabled');

            }
        });
    }
    return false;
});

My processing logic in the controller looks like

    def bulkaction
            if request.post?
                ids = params[:ids]
                #Need to create a function here to parse out my string
                puts ids #for testing purposes, just put my ids onto the console
            end

puts "This function was accessed and ran."
end

And finally the console says

Processing UserController#bulkaction (for ::ffff:xx.xxx.xxx.xxx at 2009-07-06 23                                                                             :29:49) [POST]
  Parameters: {"ids"=>"Purchases 10040963"}

ActionController::InvalidAuthenticityToken (ActionController::InvalidAuthenticit                                                                             yToken):
  /usr/local/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
  /usr/local/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
  /usr/local/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
  /usr/local/lib/ruby/1.8/webrick/server.rb:162:in `start'
  /usr/local/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'
  /usr/local/lib/ruby/1.8/webrick/server.rb:95:in `start'
  /usr/local/lib/ruby/1.8/webrick/server.rb:92:in `each'
  /usr/local/lib/ruby/1.8/webrick/server.rb:92:in `start'
  /usr/local/lib/ruby/1.8/webrick/server.rb:23:in `start'
  /usr/local/lib/ruby/1.8/webrick/server.rb:82:in `start'

It would be very helpful if someone were able to tell me where I was going wrong.

  • 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-05-12T00:28:22+00:00Added an answer on May 12, 2026 at 12:28 am

    Solved! changed the ajax to

    data: "=" + action + "&ids=" + ids + "&authenticity_token=" + AUTH_TOKEN,
    

    And I added to the head for each page

    <%= javascript_tag "const AUTH_TOKEN = #{form_authenticity_token.inspect};" if protect_against_forgery? %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 281k
  • Answers 281k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer What format are you using for your webpage? Will this… May 13, 2026 at 3:53 pm
  • Editorial Team
    Editorial Team added an answer Use unicode: ... = content.replace(/\u201C/g, '"'); You can find unicode… May 13, 2026 at 3:53 pm
  • Editorial Team
    Editorial Team added an answer You want to use the INTERSECT operator to get those… May 13, 2026 at 3:53 pm

Related Questions

Okay so from what I've read on other websites and on stack overflow, Rails
At work we have two competing theories for salts. The products I work on
Okay so I'm pulling in an XML feed from feedburner, using an XMLDataSource and
Okay so i set up this thing so that I can print out page
Okay so I want to make an application that launches other applications. However, the

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.