2012-12-17 155 views
0

我們有一個由rails 3.1.8開發的工具,可以將產品信息導出到ms字,然後產品所有者可以點擊我們應用中的鏈接來編輯產品詳細信息。ms word的打開鏈接

這裏是問題:當我們點擊鏈接的話,它會轉到主頁而不是編輯頁面。

所以我們用設計來進行認證,在路線:

devise_for :users do 
    get "login" => "devise/sessions#new" 
    get "logout" => "devise/sessions#destroy" 
end 

開發日誌:

Started GET "/products/24/edit" for 10.237.133.26 at 2012-12-17 15:24:49 +0800 
    Processing by ProductsController#edit as */* 
    Parameters: {"id"=>"24"} 
Completed in 4ms 

Session: {"as:products"=>{:list=>{}}, "input_device_type"=>"MOUSE", "hover_supported"=>true, "user_return_to"=>"/products/24/edit", "flash"=>#<ActionDispatch::Flash::FlashHash:0x00000006c80540 @used=#<Set: {}>, @closed=false, @flashes={:alert=>"You need to sign in or sign up before continuing."}, @now=nil>, "_csrf_token"=>"xvfpiA69SZas+iHoCy5NQRMOifXtomG3RoLaYvPQsSw="} 


Started GET "https://stackoverflow.com/users/sign_in" for 10.237.133.26 at 2012-12-17 15:24:49 +0800 
Processing by Devise::SessionsController#new as */* 
Rendered devise/shared/_links.erb (0.1ms) 
Rendered devise/sessions/new.html.erb within layouts/activescaffold (3.3ms) 
Rendered layouts/_header.html.erb (50.0ms) 
Rendered layouts/_menu.html.erb (3.4ms) 
Rendered layouts/_footer.html.erb (0.0ms) 
Completed 200 OK in 91ms (Views: 62.7ms | ActiveRecord: 3.3ms) 


Started GET "https://stackoverflow.com/users/sign_in" for 10.237.133.26 at 2012-12-17 15:24:50 +0800 
    Processing by Devise::SessionsController#new as HTML 
    User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = 15 LIMIT 1 
Redirected to http:// localhost:30033/ 
Completed 302 Found in 33ms 

Session: {"input_device_type"=>"MOUSE", "hover_supported"=>true, "_csrf_token"=>"Pa8zGbsbms4EwRUO4G7MyJFv7ztKe33WICeY7qpYgeQ=", "warden.user.user.key"=>["User", [15], nil], "flash"=>#<ActionDispatch::Flash::FlashHash:0x00000006fec508 @used=#<Set: {}>, @closed=false, @flashes={:alert=>"You are already signed in."}, @now=nil>} 


Started GET "/" for 10.237.133.26 at 2012-12-17 15:24:51 +0800 
    Processing by WelcomeController#index as HTML 
    User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = 15 LIMIT 1 
Rendered welcome/index.html.erb within layouts/application (0.0ms) 
Rendered layouts/_header.html.erb (3.8ms) 
Rendered layouts/_menu.html.erb (3.6ms) 
Rendered layouts/_footer.html.erb (0.1ms) 
Completed 200 OK in 45ms (Views: 14.0ms | ActiveRecord: 4.3ms) 

有誰有更好的解決方案?

+0

我試試這個提議的情況下很好地解決,似乎不工作:https://github.com/plataformatec/devise/wiki/How-To:-Redirect-back當前頁面後登錄,註銷,註冊,更新 –

回答

0

Microsoft Office有其自己的機制來識別鏈接(即協議發現)。

這需要在rails中進行不同的處理。微軟辦公室使用OPTIONS http方法發出請求,隨後直到前200個響應,然後在瀏覽器窗口中打開相同的URL(在您的案例中重定向的url)。

在這裏,Devise跟蹤會話內的requested_url,但瀏覽器使用登錄URL發起新會話,因此設計者無法將其重定向回鏈接單擊ms doc內。

這裏是處理 http://rails.nuvvo.com/lesson/2318-dealing-with-microsoft-office-protocol-discovery-in-rails

+0

對不起,我進行了測試並處理了一些緊急問題。我打印請求並發現了request_method的部分,它向我們展示'GET',而不是選項。 @ request_method =「GET」,@filtered_pa​​rameters = {「action」=>「edit」,「controller」=>「products」,「id」=>「3861」},@ method =「GET」,@ fullpath =「 /產品/ 3861 /編輯「> –