2
I have a web application and am accessing through an APP this way:
.controller('LoginCtrl', function($scope, $ionicPopup, $state, $http) {
    $scope.data = {};
    $scope.login = function() {
        $http.post('http://localhost:3000/login', $scope.data.session_email, $scope.data.session_password).success(function(data) {
            $state.go('improvements');
        }).error(function(data) {
            var alertPopup = $ionicPopup.alert({
                title: 'Login failed!',
                template: 'User/Password is Wrong'
            });
        });
    }
});
but I’m getting the following error:
NoMethodError (undefined method `[]' for nil:NilClass):
  app/controllers/sessions_controller.rb:9:in `create'
My controller:
def create
    user = User.find_by(email: params[:session][:email].downcase)
    if user && user.authenticate(params[:session][:password]) && user.permission == true
      params[:session][:remember_me] == '1' ? remember(user) : forget(user)
      remember user
      redirect_to user
    elsif user && user.permission == false
      flash.now[:notpermission] = "You do not have a permission"
      render "new"
    else
      flash.now[:error] = "Invalid password or email"
      render "new"
    end
  end
I know I need the token to access but I don’t know how to do it... someone can give me a light ?
in Which module you are adding this controller, this module was injected into the application ??
– Renan Degrandi
I forgot to mention this controller at the bottom in case it is the web application I want to access and the controller at the top is the APP
– archibald
Look, it’s hard to say but in its code lines the POST method is wrong, ( $http.post('http://localhost:3000/login', $Scope.data.session_email, $Scope.data.session_password)) you are passing 2 parameters and the post waits (URL, OBJECT) then either you call via GET and pass these two parameters in the URL, or pass a JSON OBJECT to the server
– Renan Degrandi
just exchange the get for the post ?
– archibald
It worked with the get perfectly thank you.
– archibald
I’ll add an answer for you to make official, @Archibald
– Renan Degrandi