dha*_*ech 3 ruby-on-rails ruby-on-rails-3 railstutorial.org
Rails教程的10.2.1部分使用了before_filter不推荐使用的部分.编写代码UsersController以便不使用的现代惯用方法是before_filter什么?
这edit是我尝试的版本:
def edit
if ( signed_in? )
@title = "Edit user"
else
deny_access
end
end
Run Code Online (Sandbox Code Playgroud)
但是,这会在我运行rspec时触发2次失败.
rspec ./spec/requests/friendly_forwardings_spec.rb:6 # FriendlyForwardings should forward to the requested page after signin
rspec ./spec/controllers/users_controller_spec.rb:266 # UsersController authentication of edit/update pages for non-signed-in users should deny access to 'edit'
Run Code Online (Sandbox Code Playgroud)
num*_*407 11
before_filter不推荐使用.你可能会感到困惑,因为定义是AbstractController::Callbacks从ActionController::Filters::ClassMethodsRails 3 转移到了它,但它仍然非常活跃和踢.
在Rails 3.1中定义了这个免费的免费版:https:
//github.com/rails/rails/blob/v3.1.0.rc6/actionpack/lib/abstract_controller/callbacks.rb#L80