How to use rails method in .js.erb and pass it javascript argument?

136 views Asked by At

I have a .js.erb file and I'm trying to make it possible to write comments. I have two tabs: write and preview. When you click on 'preview' tab, markdown preview should be displayed. Now, I'm using Redcarpet and stuff from RailsCast272, so my markdown function is in application_helper.rb file:

  def markdown(text)
    markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML)
    return markdown.render(text).html_safe
  end

How to I use it in .js.erb file and pass it a value of a tag? I get error "undefined local variable or method `markdown'"?

Thanks

0

There are 0 answers