开发者

Ruby on Rails Filters Applied to View

I'm looking to create an application that can add 'filters' to a view after it has been rendered. For example, if my view renders to:

"<html><body>demo</body></html>"

I want to capitalize all letters so it looks like:

开发者_JAVA技巧
"<HTML><BODY>DEMO</BODY></HTML>"

Any ideas on how to do this? Thanks!


Simple version (in app/controllers/application_controller.rb):

after_filter do |c|
  c.response.body = c.response.body.upcase
end

However, this is probably bad since it will literally uppercase everything. You probably want to restrict it to only HTML responses and, even then, you'll want to make sure it doesn't create invalid markup (for example, it should ignore <script> tags and the like).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜