jeudi 18 février 2016

How to make Angular and Rails interact? Unknown format error

I have ngResource directive included in my first project in order to be able to interact with RESTful Api.

Then I setup my factory like this:

angular.module('app').factory('User', [
  '$resource', function($resource) {
    return $resource('/api/user_login/:id', { id: '@id' }, {
      update: { method: 'PUT' }
    });
  }
]);

In my controller I try to save User i.e to send POST request.

app.controller('loginCtrl', [
  '$scope', 'User', function($scope, User) {
    return User.save();
  }
]);

My second project's controller look like the following. I'm trying to reference create action.

class UserSessionsController < UserApplicationController
  respond_to :js, only: :create

  def create
    if @counterparty
      session[:counterparty_id] = @counterparty.id
      @counterparty.update(signed_in: true)
    else
      flash.now[:error] = 'Invalid email or password'
    end

    respond_with(@counterparty, layout: false)
  end
end

As a result I'm getting ActionController::UnknownFormat.

enter image description here

How can I solve this?

Aucun commentaire:

Enregistrer un commentaire