设计 - sign_in()不工作轨道5.2.0

时间:2018-05-01 01:59:31

标签: ruby-on-rails ruby devise

创建了新的ruby应用

在我的控制器中我试图像这样登录用户

    email = params[:email]
    password = params[:password]

    user = User.authenticate(email, password)

    if user 
        sign_in(user)

        redirect_to root_path
    else

        render json: {success: false}
    end

用户进入sign_in

控制台正在打印:

Processing by AccountController#sign_in_user as */*
  Parameters: {"password"=>"[FILTERED]", "email"=>"email@live.com", "subdomain"=>"app"}
  User Load (1.9ms)  SELECT  "users".* FROM "users" WHERE "users"."email" = $1 ORDER BY "users"."id" ASC LIMIT $2  [["email", "email@live.com"], ["LIMIT", 1]]
  ↳ app/models/user.rb:9
  User Load (0.5ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2  [["id", 2], ["LIMIT", 1]]
  ↳ app/controllers/account_controller.rb:11
Redirected to http://app.lvh.me:3000/
Completed 200 OK in 131ms (ActiveRecord: 2.4ms)

然后重定向到我认证用户的根路径并给我一个401

    Started GET "/" for 127.0.0.1 at 2018-04-30 21:53:39 -0400
Processing by DashboardController#index as HTML
  Parameters: {"subdomain"=>"app"}
Completed 401 Unauthorized in 1ms (ActiveRecord: 0.0ms)

在数据库中,用户的current_sign_in,last_sign_in,ect ..正在更新

我已多次这样做了,我不确定为什么它不起作用,有什么想法?

1 个答案:

答案 0 :(得分:0)

经过一个小时的疯狂之后

我的路线中有一条随机线

  devise_for :users

没有结束什么都没做,这导致了这个问题。

删除后一切都很好。