我正在开发一个简单的Rails 3.2应用程序。我一直关注Ruby on Rails Tutorial来管理用户和会话(cookies)。我尝试退出时发生路由错误。它在我的桌面计算机上没有任何错误,但是当我尝试我的iOS设备(来自Heroku)时,它给我一个路由错误。
点击Heroku上的注销后,我收到以下错误:
The page you were looking for doesn't exist.
You may have mistyped the address or the page may have moved
With the url: .../sessions#
我不知道网址中#
的来源。
如果我在本地计算机上尝试,使用iOS模拟器或将我的设备连接到我的IP地址,我会收到以下错误:
Started DELETE "/sessions" for 127.0.0.1 at 2012-04-23 18:10:41 +0200
ActionController::RoutingError (No route matches [DELETE] "/sessions"):
With the url: .../sessions#
同样,我不知道网址中#
的来源。
我的路线如下:
resources :sessions, only: [:new, :create, :destroy]
match '/signup', to: 'users#new'
match '/signin', to: 'sessions#new'
match '/signout', to: 'sessions#destroy', via: :delete
我的SessionsController看起来像这样:
def new
end
def create
user = User.find_by_email(params[:email])
if user && user.authenticate(params[:password])
sign_in user
redirect_to root_path
else
render 'new'
end
end
def destroy
sign_out
redirect_to root_path
end
位于我的SessionsHelper中的我的注销方法如下所示:
def sign_out
current_user = nil
cookies.delete(:remember_token)
end
我的退出链接如下所示:
<%= link_to "Sign out", signout_path, method: "delete", "data-icon" => "arrow-r", "data-iconpos" => "right", "data-theme" => "b", :class => "ui-btn-right", "data-ajax" => "false" %>
注意,我使用jQuery mobile来设计移动版本的样式。
有谁知道我做错了什么,或者导致错误的原因是什么?
为了完成,当我运行rake路线时,我得到以下结果:
root / pages#home
[...]
sessions POST /sessions(.:format) sessions#create
new_session GET /sessions/new(.:format) sessions#new
session DELETE /sessions/:id(.:format) sessions#destroy
[...]
谢谢!