English 中文(简体)
铁路资源——干扰控制器?
原标题:Rails resource_controller with interruption?
  • 时间:2009-08-31 09:53:52
  •  标签:

如果处理工作不符合某些标准(例如,所涉物体并非由此类用户拥有等),我想先采取行动以选择性方式中断处理。

I need to use this because I have a more complicated scenario that I need the object to be loaded before the access rights could be determined, so I would have situations where I want to interrupt the action if it is invalid access, anyway I could achieve this?

最佳回答

在与驻地协调员合作时,这是我所想的。

通常的驻地协调员行动类似:

def show
  load_object
  before :show
  response_for :show
rescue ActiveRecord::RecordNotFound
  response_for :show_fails
end

因此,如果某些条件失败,你想在装货后打断显示。

我认为(除修改驻地协调员外)这样做的最佳方式是:

  • use before_filter to check the condition
  • in the the before_filter use the object or collection helpers (according to the action). this way the load_object/load_collection in the RC action implementation will use the same value cached from your usage of the helper so no extra queries will be made.
问题回答

假设你指的是<代码>_filter:

任何<条码> 电话应当打破过滤链和操作。 因此,简单地把你的出入控制过滤器放在负荷后,然后发出错误信息(有适当的地位代码,用于完善的网页卡拉马,并防止一只 w子被击落)。

只要你不认为太困难,它就只能是另一个铁路区。

任何帮助或我是否失踪?

维塔利办法或许是正确的,但我也采取令人感兴趣的超目标做法,以作为参考:

  1. Use around_filter
  2. At the before hook, throw AccessDeniedException
  3. Capture the exception in the around filter

这也是工作。

如果你在“资格审查”之前发现 writing字,那么你会发现

还为易于与资源——控制者融合而建造。





相关问题
热门标签