POST payload to rails model t.json 'payload'

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

POST payload to rails model t.json 'payload'

Loua Max Desire

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 [hidden email].
To post to this group, send email to [hidden email].
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.
Reply | Threaded
Open this post in threaded view
|

Re: POST payload to rails model t.json 'payload'

Hassan Schroeder-2
On Thu, Apr 5, 2018 at 9:56 AM, Loua Max Desire <[hidden email]> wrote:

> 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 :/.

What is actually arriving as the raw params -- are you inspecting it
via logging statements or pry or ??

Have you tried submitting a properly-shaped payload via e.g. curl
or wget to confirm your controller action is handling it correctly?

--
Hassan Schroeder ------------------------ [hidden email]
twitter: @hassan
Consulting Availability : Silicon Valley or remote

--
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CACmC4yA96b%3DufmT42S6CxZ6-37naN-npk57x8EOX3YASOa8oFw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.