[关闭]
@guochy2012 2014-01-10T07:54:26.000000Z 字数 442 阅读 1029

第九章的测试

注意要去调用signin方法

先实现修改的功能 
再去进行权限控制
1.用户必须登陆
2.用户只能编辑自己的资料
3.实现更友好的转向

如何实现友好转向

在helper里面定义好redirect_back_or方法
定义storelocation方法

在sign_in_redirect中调用存储功能
在登陆后的跳转功能上调用前面的redirect_back_or
  1. def redirect_back_or(default)
  2. redirect_to(session[:return_to] || default)
  3. session.delete(:return_to)
  4. end
  5. def store_location
  6. session[:return_to] = request.fullpath if request.get?
  7. end
  1. def signed_in_user
  2. unless signed_in?
  3. store_location
  4. redirect_to signin_url, notice: "Please sign in."
  5. end
  6. end
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注