• 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

###Rails2.1以降
2.1以降はview以外からhelpersにアクセスできるようになるようです。via 瀧内さん
rails>>
ApplicationController.helpers.simple_format(text)
<<--
http://www.nomedojogo.com/livro/carlosbrando-rubyonrails21_en.pdfより

###Rails2.1以前
私の現状の環境では2.1でないので、ぐぐってみたらいい感じのがありました。
http://snippets.dzone.com/posts/show/1799

ApplicationControllerに挿入すればok
rails>>
def help
Helper.instance
end

class Helper
include Singleton
include ActionView::Helpers::TextHelper

def h(string)  
  ERB::Util.html_escape(string)
end

end
<<--
(注)オリジナルのsnippetにdef hを追加しています。

posted by satoko satoko on Fri 25 Jul 2008 at 05:51 with 2 comments