jejacks0n / mercury

Mercury Editor: The Rails WYSIWYG editor that allows embedding full page editing capabilities directly inline.
http://jejacks0n.github.com/mercury
Other
2.63k stars 531 forks source link

Saving Without Rails #420

Closed mmsheeks closed 10 years ago

mmsheeks commented 10 years ago

Hello folks.

I've been working on implementing your editor, and it looks wonderful, but I have a problem. My webhost doesn't support Rails, they claim to, but it's limited in too many ways and is thus crippled.

I have everything implemented with the exception of a functioning save pattern. Any pointers on how I might be able to get the editor to POST the html content of the full region I'm working in to another file for saving?

jejacks0n commented 10 years ago

It's in the readme. For more info, please refer to that. I've pasted in the relevant information.

jQuery(window).on('mercury:ready', function() {
  Mercury.saveUrl = '/contents';
});
jejacks0n commented 10 years ago

If you want to save it, check ruby's File.open.

mmsheeks commented 10 years ago

First off, I read the readme before posting this, as well as all of your previous issues for saving.

I do not have ruby on my host machine, as my OP points out, so I don't really understand why you would think I can use a function that requires ruby.

I implemented the Mercury.saveUrl fix on mine, but I continuously get the "Mercury failed to save to..." error.

Thanks for the quick response, but can you try to be a little more thorough with your next response?

jejacks0n commented 10 years ago

heh, I did read it.. you didn't specify that it didn't have any back end support, and that your host claims to support Rails (which is ruby btw). If you don't have ruby, then what do you have? PHP maybe? and if you don't have anything, how would you expect to handle a POST submission? Maybe you want to clarify a little bit more before you start throwing attitude. I went off the poor information you provided, which basically reads "I don't know how to save, help me with that".

mmsheeks commented 10 years ago

Sorry. It's been a really long week full of plenty of frustrating things, not that that's an excuse, but...yeah.

Anywho.

The host supports a LAMP environment, so I have PHP 5.4, but no real ruby support. What I'm trying to get to happen is to have the HTML content passed to the other page in POST so that I can save it to a mysql database using PHP and MySQLi.

They claim to support ruby ( and Rails) but they restrict you from doing any action that would alter the server or submit data or...well, do anything really. So, it's a crippled service.

If you can excuse my frustration, I'd really appreciate any help you could provide. Could really use a win here.

jejacks0n commented 10 years ago

I haven't done php for a while now. This code expects that you only have a single page.

mercury_save_to_file.php

<?php
file_put_contents('path/to/filename', $POST['content']);
?>

I don't believe this code will work as is, and will require you to play around with it before it works.. eg, I don't recall if the save submits the content within 'content' or whatever.. you can use print_r $POST to see what's being submitted to debug that.

jejacks0n commented 10 years ago

Adjust your save url in the previous example to point to mercury_save_to_file.php

mmsheeks commented 10 years ago

Okay. So I'm using the default save action, and I put the file mercury_save_to_file.php, with the code snippet in your post at my document root. Now I get the "Mercury was unable to save to ./mercury_save_to_file.php" as the error.

The tree looks like this

-js --mercury ----all mercury files -index.php -mercury_save_to_file.php -save.php

Do I need to move things around so that the mercury_save_to_file is inside the same folder as the mercury js files? I guess I could try providing the exact path rather than a relative path, but that becomes very non-portable. Any thoughts?

jejacks0n commented 10 years ago

It's apparent that you may need more help than I'm able to provide (I have a job that pays my salary). I'm sorry you're struggling with frustration, and I feel your pain. Do you have a php/back end person that can help you?

mmsheeks commented 10 years ago

I suppose I will just need to futz with it more then. I am the lead web developer for the site. I'll play around with it, see if I can't figure out why Mercury can't seem to find the files I'm pointing it at. Thanks for your help.

mmsheeks commented 10 years ago

AHAH! Alright, figured it out. Instructed Mercury to fire off a javascript function when clicked. the javascript function gets the HTML content of the editor, then uses jQuery.post() to send the data to the save script.

jejacks0n commented 10 years ago

That's pretty much what it does already, but glad you figured it out.

mmsheeks commented 10 years ago

I figured as much. Not sure why it wasn't working in the first place, worth looking into, but some other time when the project doesn't have a deadline. For now I have a functioning solution. I think it may have been having some trouble with finding elements within the iFrame, but I'm not certain. In any case, forward movement.

mpfrenette commented 10 years ago

For those who decided to read this issue and couldn't figure out how to fix it, here is how to do it.

Simply add the following code in your head section, inside a <script type="text/javascript"> tag:

jQuery(window).on('mercury:ready', function() { Mercury.PageEditor.prototype.save = function() { var data = this.serialize(); jQuery.post('YOUR URL', data ); } });