开发者

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://gith开发者_Go百科ub.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


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜