samedi 16 décembre 2017

Ember Data unable to pass params to Rails properly via createRecord

I'm trying to set up an Ember Data call to create a signup object, which just contains an email and nothing more. Something is funky with my Ember Data setup because the params seem to be passed but Rails is unable to receive them. Not sure what's wrong.

Ember frontend:

  var signup = this.get('store').createRecord('signup', {
    email: this.get('emailAddress')
  });
  console.log(this.get('emailAddress')); --> prints fine
  console.log(signup); --> data is empty, somewhat alarming/confusing
  console.log(signup.get('email')); --> however, this also prints fine
  signup.save();

Request payload:

{"data":{"attributes":{"email":"gg@gg.com"},"type":"signups"}}

Rails backend:

  def create
    @signup = Signup.new({ email: params[:email] })
    p params
    # prints <ActionController::Parameters {"controller"=>"signups", "action"=>"create"} permitted: false>

    p @signup --> prints Signup object with nil for email
    @signup.save!
    render json: @signup
  end

Response payload:

{"data":{"id":"3","type":"signup","attributes":{"email":null}}}




Aucun commentaire:

Enregistrer un commentaire