I would like to have a live preview similar to the one here on stackoverflow. Using Rails 3.1 and RedCloth, I can not seem to understand how to make it work.
I tried making my own Ajax call such as this (inside my posts.js.coffee)
$ ->
$('#post_content').keyup ->
$.post('posts/preview', $('#post_content').val(), null, "script")
and having a function inside the controller
def preview
@content = params[:post_content]
respond_to do |f|
f.js
end
end
in preview.js.erb I put
$("#preview").html("<% raw RedCloth.new(@content).to_html %>");
I added the resource
resources :post do
post 'preview', :on => :collection
end
but it doesn't work. Any suggestions?