2011-04-14 34 views
0

設計1.2 軌3.0.5色器件重定向到登錄和註銷用戶在表單提交

我有這個在我的控制器:before_filter :authenticate_user! 當一個表單提交,我重定向到登錄頁面,並用戶會自動註銷。即使他們已經登錄,這似乎是發生在表單上。這是有問題的操作:

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

筆者認爲:

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

引發JS如下:

$("form").submit(); 

任何想法,爲什麼這會發生?找不到任何有用的信息...

+0

升級到最新的軌道,似乎這樣做。似乎是軌道問題 – 2011-04-15 07:27:05

回答

2

看起來您可能以其他方式解決了您的問題,但我遇到了類似的問題,最終導致我的表單上丟失了真實性標記。該視圖並未使用Rails form_for helper,因此表單提交中沒有包含authenticity_token。

即。

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

改爲

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

結果

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

更多細節上authenticity_token:Understanding the Rails Authenticity Token

+0

但是,您如何使用Curl註銷?它只是重定向我登錄和不發送json回:http://stackoverflow.com/questions/7997009/rails-3-calling-destroy-method-with-curl – JohnMerlino 2011-11-04 14:42:06