Closed deanchester closed 12 years ago
I'm not sure this is enough information to provide you help. Have you opened up the debug console in chrome or FF to see if Mercury is making a request? What is the url you are trying to save to? What does your routes file look like, i.e. what is the route definition you are using to try to have Mercury save to?
In the console in chrome I'm getting this error:
POST http://localhost:3000/pages/1 404 (Not Found) jquery-1.7.js:8158 jQuery.ajaxTransport.send jquery-1.7.js:8158 jQuery.extend.ajax jquery-1.7.js:7636 PageEditor.save page_editor.js:389 (anonymous function) page_editor.js:216 jQuery.event.dispatch jquery-1.7.js:3320 jQuery.event.add.elemData.handle.eventHandle jquery-1.7.js:2926 jQuery.event.trigger jquery-1.7.js:3208 jQuery.fn.extend.trigger jquery-1.7.js:3844 jQuery.extend.each jquery-1.7.js:661 jQuery.fn.jQuery.each jquery-1.7.js:275 jQuery.fn.extend.trigger jquery-1.7.js:3843 jQuery.extend.trigger mercury.js:30 Mercury.Toolbar.Button.Button.handleClick toolbar.button.js:167 Mercury.Toolbar.Button.Button.bindEvents toolbar.button.js:131 jQuery.event.dispatch jquery-1.7.js:3320 jQuery.event.add.elemData.handle.eventHandle jquery-1.7.js:2926
In my routes file I have: resources :pages do member { post :mercury_update } end
It's posting to the pages update path which is not a valid path for rails. How are you trying to set the 'save-url' data attribute on your edit link?
Like so: <%= link_to "Edit Page", "/editor" + request.path, id: "edit_link", data: {save_url: mercury_update_page_path(@page)} %>
Try Mercury.on 'ready' instead of $(window).bind 'mercury:ready' and see if you still get the double fire. It might also be worth checking that you actually have a valid url before setting mercury so that it doesn't reset the saveUrl with a null value. I am currently not working off of mercury/master so not sure if the double event is a regression that was introduced while others have been making updates.
I'm still getting it to be double fired. If it helps in the i've tried setting the update URL statically in the HTML file like so:
var saveUrl = 'http://localhost:3000/pages/1/mercury_update';
And its still failing.
As well as this i've moved to the new way(not the one mentioned in the railscasts to set the save url so like so:
onload: function() { //Mercury.PageEditor.prototype.iframeSrc = function(url) { return '/testing'; } Mercury.on('ready', function() { var link = $('#mercury_iframe').contents().find('#edit_link'); Mercury.saveURL = link.data('save-url'); Mercury.saveUrl = link.data('save-url'); console.log(Mercury); }); Mercury.on('saved', function() { window.location.href = window.location.href.replace(/\/editor\//i, '/'); }); }
In the log the saveURL and saveUrl are undefined.
I managed to fix this issue by adding this in to my rails template:
<script>
jQuery(window).on('mercury:ready', function() { Mercury.saveUrl = '/pages/' + <%= @page.id %> +"/mercury_update"; });
</script>
Add the following javascript snippet to your rails template
<script>
function onMercuryReady() { Mercury.saveUrl = '/pages/' + <%= @page.id %> +"/mercury_update"; };
</script>
Where would this line go? In a views page or in the .js file?
You can inject this is the template (.erb) file directly. No need for .js file
I've followed the RailsCast as best I could (running rails 3.2.8) using the latest commit in the repo, but my changes aren't being saved. I added an alert to output the URL to which it was saving as it was not appearing in the rails console log. And I noticed that the Alert box was appearing twice, once with the URL as it should be the next it would be blank. So what is going wrong. Here is what the ready function looks like: $(window).bind('mercury:ready', function() { var link = $('#mercury_iframe').contents().find('#edit_link'); Mercury.saveURL = link.data('save-url'); alert(Mercury.saveURL); // Line I added to see whether the URL was correct. link.hide(); });