开发者

How to skip before filters for json/xml requests in rails

开发者 https://www.devze.com 2023-01-06 07:47 出处:网络
I found a way to skip before filters based on the format, as seen below, but I\'m wondering if there is a better way since this clutters things and isn\'t very DRY.

I found a way to skip before filters based on the format, as seen below, but I'm wondering if there is a better way since this clutters things and isn't very DRY.

before_filter do |controller|
  :current_cart unless contr开发者_JAVA技巧oller.request.format.js?
end

If I don't do this, json requests fail because the current_cart method, and other methods, do things only meant for html.


You could do it this way:

before_filter :current_cart, :unless => :format_js?

def format_js?
  request.format.js?
end

Hope this helps.

0

精彩评论

暂无评论...
验证码 换一张
取 消