$(function(){ $('.redactor').redactor(getRedactorOptions()); }); function getRedactorOptions() { var csrf_token = $('meta[name=csrf-token]').attr('content'); var csrf_param = $('meta[name=csrf-param]').attr('content'); var params; if (csrf_param !== undefined && csrf_token !== undefined) { params = csrf_param + "=" + encodeURIComponent(csrf_token); }; return { imageUpload:"/redactor_rails/pictures?" + params, imageGetJson: "/redactor_rails/pictures", path:"/assets/redactor-rails" }; }