Stussa
Stussa

Reputation: 3415

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:

"<HTML><BODY>DEMO</BODY></HTML>"

Any ideas on how to do this? Thanks!

Upvotes: 1

Views: 357

Answers (1)

Brian Donovan
Brian Donovan

Reputation: 8390

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).

Upvotes: 2

Related Questions