我在rails 3應用程序上使用mobile_detection爲移動用戶提供單獨的頁面。我正在通過Safari中的用戶代理進行測試。問題出在我的一個進程上,rails發佈的網頁瀏覽器URL欄的URL與實際加載的頁面不同。所以,如果我刷新頁面,它會嘗試去錯誤地將它放在網頁欄中。Rails - 顯示的URL與頁面加載不同
這是過程。
- 用戶提交參與表格。
- 參與控制器保存記錄,然後渲染移動版或html版團隊#候選人。
以下是排除某些詳細信息的過程的服務器日誌。
Started POST "/participations" for 127.0.0.1 at 2013-07-20 00:14:37 -0400
Processing by ParticipationsController#create as HTML
...Commits to DB
Redirected to http://localhost:3000/teams/57/candidate
Started GET "/teams/57/candidate" for 127.0.0.1 at 2013-07-20 00:14:37 -0400
Processing by TeamsController#candidate as HTML
Rendered teams/candidate.mobile.erb within layouts/application (34.9ms)
當我從桌面運行相同的進程時,錯誤不會發生。作爲問題的夏天:
- Rails確實加載了groups/candidate.mobile.erb頁面。
- 不過,頁面加載後會顯示地址欄/參股
這不會從桌面上出現。
下面是參與控制器。它有一些複雜的邏輯,但本質上它是檢測記錄是否已經創建,並針對這種情況做了不同的事情,以及針對移動的情況。
DEF創建 @participation = Participation.new(PARAMS [:參與]) @team = @ participation.team
respond_to do |format|
if @participation.save
if mobile_device?
format.mobile {redirect_to candidate_team_path(@team), notice: 'You have joined the team!'}
else
format.html { redirect_to candidate_team_path(@team), notice: 'You have successfully joined the team.' }
end
else
if @participation.team_id.nil?
format.mobile { redirect_to :back, notice: 'No team was joined.' }
format.html { redirect_to :back, notice: 'No team was joined.' }
format.json { render json: @participation.errors, status: :unprocessable_entity }
else
if mobile_device?
format.mobile {redirect_to candidate_team_path(@team), notice: 'Welcome back.'}
else
format.html {redirect_to candidate_team_path(@team), notice: 'Welcome back.'}
end
end
end
end
端