在我的控制器中,我有以下内容:
before_filter :authenticated?, :only => [:edit]
def authenticated?
if current_user != User.find(params[:id])
flash[:alert] = 'Log in!'
redirect_to login_path :status => 401
end
end
现在当我登录并且我去编辑用户时,一切正常,但是当我去编辑用户时,我不应该得到以下内容:
No route matches {:action=>"new", :controller=>"sessions", :status=>401}
这是为什么?作为参考,我在下面列出了我的佣金路线。
users GET /users(.:format) {:action=>"index", :controller=>"users"}
POST /users(.:format) {:action=>"create", :controller=>"users"}
new_user GET /users/new(.:format) {:action=>"new", :controller=>"users"}
edit_user GET /users/:id/edit(.:format) {:action=>"edit", :controller=>"users"}
user GET /users/:id(.:format) {:action=>"show", :controller=>"users"}
PUT /users/:id(.:format) {:action=>"update", :controller=>"users"}
DELETE /users/:id(.:format) {:action=>"destroy", :controller=>"users"}
sessions POST /sessions(.:format) {:action=>"create", :controller=>"sessions"}
new_session GET/sessions/new(.:format) {:action=>"new", :controller=>"sessions"}
session DELETE /sessions/:id(.:format) {:action=>"destroy", :controller=>"sessions"}
root / {:controller=>"pages", :action=>"home"}
contact /contact(.:format) {:controller=>"pages", :action=>"contact"}
about /about(.:format) {:controller=>"pages", :action=>"about"}
help /help(.:format) {:controller=>"pages", :action=>"help"}
signup /signup(.:format) {:controller=>"users", :action=>"new"}
/signup(.:format) {:controller=>"users", :action=>"new"}
signout /signout(.:format) {:controller=>"sessions", :action=>"destroy"}
signin /signin(.:format) {:controller=>"sessions", :action=>"new"}
答案 0 :(得分:1)
我甚至没有看到login_path
,但您应该能够重定向到signin_path
。
无论如何,:status
部分是否对您的需求至关重要?