I’m attempting to add Mercury editor and while modifying the layout for it, it suggests to add some javascript into the view layout. Obviously the following won’t quite work, but it expresses the gist of what I’m attempting to accomplish. You’ll want to look at the section within the :javascript filter, on down where I add the - to begin the if statement for what I mean:
...
%body{ :class => "#{controller_name} #{action_name}" }
:javascript
var saveUrl = null; // Set to the url that you want to save any given page to.
var options = {
saveStyle: null, // 'form', or 'json' (default json)
saveMethod: null, // 'POST', or 'PUT', (create, vs. update -- default POST)
visible: null // if the interface should start visible or not (default true)
};
//<!-- Mix in any configurations provided through Rails.application.config.mercury_config -->
- if Rails.application.config.respond_to?(:mercury_config)
jQuery.extend(Mercury.config,
= Rails.application.config.mercury_config.to_json.html_safe
);
- end
//<!-- Mix in any options for PageEditor provided through Rails.application.config.mercury_page_editor_config -->
- if Rails.application.config.respond_to?(:mercury_page_editor_config)
jQuery.extend(options,
= Rails.application.config.mercury_page_editor_config.to_json.html_safe
);
- end
//<!-- Instantiate the PageEditor -->
new Mercury.PageEditor(saveUrl, options);
...
Could you please provide an example of how to do this properly?
You could extract your logic to helper methods and then simply interpolate their results. Take a look.