Sam Kong
Sam Kong

Reputation: 5820

Make respond_to global in Rails 3

I am trying to make QR code for every URL of my Rails 3 app. I am using https://github.com/samvincent/rqrcode-rails3 .

My question is how I make the respond_to part work globally for every action instead of setting it for each action.

respond_to do |format|
  format.html
  format.svg { render :qrcode => request.url }
end

Thanks.

Sam

Upvotes: 0

Views: 452

Answers (1)

David Grayson
David Grayson

Reputation: 87416

I think you are trying to do things the hard way. Instead of trying to use URLs like

http://www.example.com/pages/192.svg

why not use URLs like this?

http://www.example.com/qrcode?path=/pages/192

I believe this is a much easier approach because then you don't have to worry about changing the behavior of ALL your other routes and ALL your other controllers. You just need to add one route and one controller/action to handle generating the QR codes.

If you need advice on how to implement QR codes this way, I can help you with that too, just let me know.

Upvotes: 1

Related Questions