0

我目前正在测试我的 Devise 实现——除了我的注册表单外,一切都运行良好。

闪信错误:

无效的电子邮件或密码。

然后我被定向到登录表单。

不知道我哪里错了。

报名表:

<h2>Sign Up</h2>
<%= simple_form_for(resource, :as => resource_name, :url => session_path(resource_name), :html => {:class => 'form-vertical' }) do |f| %>
  <%= f.error_notification %>
  <%= f.input :name, :autofocus => true %>
  <%= f.input :email, :required => true %>
  <%= f.input :password, :required => true %>
  <%= f.input :password_confirmation, :required => true %>
  <%= f.button :submit, 'Sign up', :class => 'button' %>
<% end %>
<% render 'devise/shared/links' %>

路线:

authenticated :user do
    root :to => 'home#index'
  end

  devise_for :users

  resources :users

  root :to => 'home#index'

  resources :songs

  get 'home/index'

  match 'home/about', :to => 'home#about'

  match 'home/contact', :to => 'home#contact'

导轨服务器:

Started POST "/users/sign_in" for 127.0.0.1 at 2013-03-01 16:42:47 +1000
Processing by Devise::SessionsController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"DxwF+dMC//5UIX5beKhzaBLjnB2xaJe7pQb/C3xNK1k=", "user"=>{"name"=>"test", "email"=>"asdfas@gmail.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "commit"=>"Sign up"}
  User Load (0.2ms)  SELECT "users".* FROM "users" WHERE "users"."email" = 'asdfas@gmail.com' LIMIT 1
Completed 401 Unauthorized in 2ms
Processing by Devise::SessionsController#new as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"DxwF+dMC//5UIX5beKhzaBLjnB2xaJe7pQb/C3xNK1k=", "user"=>{"name"=>"test", "email"=>"asdfas@gmail.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "commit"=>"Sign up"}
  Rendered /Users/thmsmxwll/.rvm/gems/ruby-1.9.3-p194/gems/devise-2.2.3/app/views/devise/shared/_links.erb (0.4ms)
  Rendered devise/sessions/new.html.erb within layouts/application (7.5ms)
  Rendered layouts/_navigation.html.erb (0.5ms)
  Rendered layouts/_messages.html.erb (0.1ms)
  Rendered layouts/_footer.html.erb (0.0ms)
Completed 200 OK in 104ms (Views: 19.1ms | ActiveRecord: 0.0ms)
4

2 回答 2

1

这是由于表单助手中的url错误,只需将其替换为,

 <%= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => {:class => 'form-vertical' }) do |f| %>

注册时,url 需要是 registration_path 而不是 session_path。

于 2013-03-01T07:36:38.987 回答
0

你有错误的注册路径。

您正在注册,但您的 rails 服务器的处理是:

Processing by Devise::SessionsController#create as HTML

上面的行表明该设计以某种方式尝试为用户创建登录会话,而不是注册。

因此,rails 正在寻找email" = 'asdfas@gmail.com您的数据库中尚未存在的行,因为您正在注册。

于 2013-03-01T07:17:34.263 回答