Skip to content
This repository has been archived by the owner on Dec 14, 2021. It is now read-only.

Any sample controller & subscribe code? #11

Open
bryanvaz opened this issue Jun 3, 2016 · 1 comment
Open

Any sample controller & subscribe code? #11

bryanvaz opened this issue Jun 3, 2016 · 1 comment

Comments

@bryanvaz
Copy link

bryanvaz commented Jun 3, 2016

Hey great Rails wrapper, just saved me a couple days (or weeks) getting medium-editor into rails.
Does anyone have any sample controller ruby code and subscribe js code to actually get the changes back into a Rails model?

@tansaku
Copy link

tansaku commented Sep 1, 2017

we're wrestling with this at the moment - haven't got it working yet, but are thinking we need something like the following:

<form action="<%= @page.slug %>" method="patch">
   <div id="static_page_body" class="editable"><%= clean_html(@page.body) %></div>
</form>
$("#static_page_form").submit(function(e){
    var form = $(this);
    $.ajax({
        url   : form.attr('action'),
        type  : form.attr('method'),
        data  : {"static_page[body]": $("#static_page_body").html()}, // data to be submitted
        success: function(response){
            alert(response); // do what you like with the response
        }
    });
    return false;
});

will update once we've got a working version - feels old and clunky to be using jQuery - feels like there maybe should be a cleaner rails helper way to do this ...

(note, inspired by https://stackoverflow.com/questions/2967066/how-do-you-override-an-existing-html-form-to-use-jquery-to-post-the-form and http://guides.rubyonrails.org/working_with_javascript_in_rails.html#unobtrusive-javascript)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants