Question

So I've implemented the Markitup bbcode editor in my Rails application and I'm currently attempting to get the preview functionality working. I followed a 4 year-old blog entry install markitup! in Ruby on Rails which got me pretty close to what I need to do. So far, when I press the preview button it renders an iframe that displays a blank template for me.

In my jquery.markitup.js I have this line as one of the options:

previewTemplatePath:    '/templates/preview',

Which will make an ajax request to retrieve the page for the route:

resources :templates do
    collection do
      get :preview
    end
  end

Currently the preview action simply sets render :layout => false so I don't duplicate html. As for the preview.html.erb page itself I simply have:

<%= bb(params[:data]) %>

And the idea behind this is to send the markup entered in the editor into the params data hash and then pass that through my bb code helper which does the parsing and returns some html.

The Problem

I don't know how to fill that params[:data] with the bb code entered into the markitup editor. Does anybody know how I can send that off?

Extra details: I thought I would include all the options I'm passing off to markItUp:

options = { id:                     '',
                    nameSpace:              '',
                    root:                   '',
                    previewInWindow:        '', // 'width=800, height=600, resizable=yes, scrollbars=yes'
                    previewAutoRefresh:     true,
                    previewPosition:        'after',
                    previewTemplatePath:    '/templates/preview',
                    previewParser:          false,
                    previewParserPath:      '',
                    previewParserVar:       'data',
                    resizeHandle:           true,
                    beforeInsert:           '',
                    afterInsert:            '',
                    onEnter:                {},
                    onShiftEnter:           {},
                    onCtrlEnter:            {},
                    onTab:                  {},
                    markupSet:          [   { /* set */ } ]
                };
Was it helpful?

Solution

The previewTemplatePath and the previewParserPath options needed to be set when I make the call to markItUp!.

The previewTemplatePath points to the view that displays the rendered preview and the previewParserPath is meant to point to your controller action that handles the parsing and data parameter. Assuming you're following dry conventions both paths should be the same as it was in my case.

For a better look at how to integrate markItUp! with rails check out the source for branch14's markupitup gem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top