devise redirecting to login and signing out user on form post
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{:nam开发者_开发技巧e => "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...
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
精彩评论