家园
def land @resource = User.new @devise_mapPing = Devise.mapPings[:user]end
land.HTML.haml
= form_for @resource,:as => :user,:url => registration_path(:user),:remote => true do = label_tag 'user[email]',raw("<h3>Stay Informed!</h3>") = text_fIEld_tag 'user[email]',nil,{:placeholder => "Your email",:required => true} %input(type="submit" name="commit" value="Add")
user.rb
class User < ActiveRecord::Base before_valIDation(:on => :create) do self.password = "none" self.password_confirmation = "none" end # Include default devise modules. Others available are: # :token_authenticatable,:encryptable,:confirmable,:lockable,:timeoutable and :omniauthable devise :database_authenticatable,:registerable,:recoverable,:rememberable,:trackable,:valIDatable # Setup accessible (or protected) attributes for your model attr_accessible :email,:password,:password_confirmation,:remember_meend
正在使用Default Devise :: RegistrationsController.
这在提交时出现:
development.log
Started POST "/users" for 127.0.0.1 at 2013-04-24 20:49:46 -0300Processing by Devise::RegistrationsController#create as Js Parameters: {"utf8"=>"✓","user"=>{"email"=>"me@mjohnst.com"},"commit"=>"Add"} [1m[35m (0.3ms)[0m BEGIN [1m[36mUser Exists (0.5ms)[0m [1mSELECT 1 AS one FROM "users" WHERE "users"."email" = 'me@mjohnst.com' liMIT 1[0m [1m[35m (0.2ms)[0m RolLBACK Rendered devise/registrations/create.Js (0.4ms)Completed 200 OK in 84ms (VIEws: 4.1ms | ActiveRecord: 1.0ms)
但是,在rails控制台中:
2.0.0p0 :011 > User.all User Load (0.5ms) SELECT "users".* FROM "users" => #<ActiveRecord::Relation []>
和localhost:5000 /用户完全是空的…
当我的数据库中没有用户时,为什么我会收到用户存在和RolLBACK?
解决方法 用户存在查询来自验证器检查没有用户使用您尝试注册的相同电子邮件.永远不会有INSERT查询,因此您的用户永远不会被注册.这可能是验证失败.在这种情况下,您的密码可能太短(默认的Devise密码长度验证要求至少长度为8,您的密码长度仅为4).
您正在收到成功的200响应,因为它正在重定向回注册,并显示一条Flash消息,说明哪些验证失败.
总结以上是内存溢出为你收集整理的ruby-on-rails – Rails设计用户存在空DB全部内容,希望文章能够帮你解决ruby-on-rails – Rails设计用户存在空DB所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)