0

devise 1.2 rails 3.0.5

I have this in my controller: before_filter :authenticate_user! When a form is submitted, i'm redirected to the log in page and the user is automatically logged out. Even though they have logged in, this seems to be happening on form post. This is the action that has the issue:

def next
  myObject = theObject.first
  myObject.current_number = params[:next_number]
  myObject.save!
  redirect_to :action => 'index'
end

In my view:

%form{:method => "post"}
%input#nextNumber{:name => "next_number", :type => "hidden", :value => "7"}/

Triggered in js as follows:

$("form").submit();

Any ideas why this would be happening? Can't find any useful info...

newbie_86
  • 4,214
  • 16
  • 53
  • 85

1 Answers1

2

Looks like you may have solved your problem in another manner but I hit a similar issue that ended up being related to a missing authenticity token on my form. The view was not using the Rails form_for helper, and as a result had no authenticity_token included in the form submission.

ie.

<form action="..." method="POST">...</form>

changed to

<%= form_for :form, :url => "..." do |f| %> ... <% end %>

results in

<form action="..." method="POST">
  <input name="authenticity_token" type="hidden" value="...">
  ...
</form>

More details on authenticity_token: Understanding the Rails Authenticity Token

Community
  • 1
  • 1
Kristian PD
  • 2,665
  • 1
  • 16
  • 22
  • But how do you sign out using Curl? It just redirects me to login and doesnt send the json back: http://stackoverflow.com/questions/7997009/rails-3-calling-destroy-method-with-curl – JohnMerlino Nov 04 '11 at 14:42