SammyLin / redactor-rails

This repo is deprecated. Please check out official gem for Redactor 2. https://github.com/Redactor2/redactor2_rails
MIT License
389 stars 254 forks source link

Autosave is not getting fired after 1st attempt #112

Open dave4u90 opened 10 years ago

dave4u90 commented 10 years ago

The autosave is not firing after firs attempt.....here is my code

At

config.js

$(document).ready( function () { 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); } $('.redactor').redactor( { "imageUpload": "/redactor_rails/pictures?" + params, "imageGetJson": "/redactor_rails/pictures", "fileUpload": "/redactor_rails/documents?" + params, "fileGetJson": "/redactor_rails/documents", "path": "/assets/redactor-rails", "css": "style.css", autosave: "/notes", autosaveInterval: 30, // seconds autosaveFormdata: true, autosaveCallback: function (json) { console.log(json); } }); });

And at

NotesController

def create() if params[:note][:id].present? @note = Note.find(params[:note][:id]) @note.update_attributes(params[:note]) else @note = Note.new(params[:note]) @note.save end if request.xhr? if @note.note_object_type == ProductInstance.class.to_s render js: "window.location.replace('#{notes_url(:product_instance_id => @note.product_instance_id.to_s)}');" else render js: "history.back();" end else if @note.note_object_type == ProductInstance.class.to_s redirect_to notes_path(:product_instance_id => @note.product_instance_id.to_s) else redirect_to :back end end end

and in the view

<%= my_form.text_area :note, class: "redactor form-control", rows: 100, columns: 100 %>

Am i missing something or wrongly coded??