Ruby on Rails Thursday, April 5, 2018

So guys i'm working on a tournament bracket based on the GOjs library, The bracket has score input. Once my user is done editing the bracket i save the bracket into a json variable :

function save() {      var tojs = myDiagram.model.toJSON();      var payload = JSON.parse(tojs);      stringify_tojs = JSON.stringify(payload);      myDiagram.isModified = false;

I use XMLHttpRequest to able to post the payload into my rails model that handles 'payload' :

var request = new XMLHttpRequest();      request.onload = callback;      request.open("post", "http://localhost:3000/malesingles");      request.setRequestHeader("Content-Type", "application/json");      request.send(payload);

I dont know where i went wrong but i'm certain it's around my controller params but i can't find my mistake already been a week, the controller looks something like this :

@tournoi = Tournoi.new(bracket_params)    if @tournoi.save      redirect_to root_url      flash[:success] = "Your tournament bracket has been validated!"    #  redirect_to @tournoi    else      render 'new'    end

end i have included the bracket_params in private settings

def bracket_params        params.require(:tournoi).permit(:payload)       end

Tried different method to post the payload none really work, would appreciate some help to understand where i went wrong, i get a param is missing or empty :/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/5ad65f2d-6432-4871-834c-494b771d19b4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment