早上好,
我的注册有问题。我一直在手动测试它,注册并没有通过字段。我已经设置了强大的参数,我也尝试过没有它们并使用旧的 attr_accessible 但它没有任何区别。
以前有没有其他人遇到过这个问题?
application_controller.rb
class ApplicationController < ActionController::Base
before_filter :configure_permitted_parameters, if: :devise_controller?
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
protected
def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:first_name, :last_name, :profile_name, :email, :password, :password_confirmation,
:confirmation_token, :confirmed_at, :confirmation_sent_at) }
end
end
用户.rb
class User < ActiveRecord::Base
before_create :create_rank
devise :omniauthable, :omniauth_providers => [:facebook]
attr_accessible :provider, :uid
validates :first_name, :last_name, :profile_name, presence: true
# validates :email, presence: true,
# :format => { :with => /^([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})$/i, :on => :create },
# :uniqueness => true,
#:multiline => true
validates :password, :presence => true,
:confirmation => true,
:length => {:within => 6..40},
:on => :create
validates :password, :confirmation => true,
:length => {:within => 6..40},
:allow_blank => true,
:on => :update
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable, :registerable, :confirmable
我很迷茫,不知道为什么会发生这个问题,我认为不是表格,但请参阅下面的表格。
设计/注册/new.html.erb
div class="span12">
<div class="row">
<div class="span3">
<div class="verticaldivide">
<h2 style="color:white;">Sign up</h2>
<%= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => {:class => "form-vertical"}) do |f| %>
<%= f.error_notification %>
<div class="control-group">
<%= f.input :first_name, :required => true, :autofocus => true, label: false, placeholder: "Bilbo", :input_html => {:class => "form-control"} %>
<br />
<%= f.input :last_name, :required => true, :autofocus => true, label: false, placeholder: "Baggins", :input_html => {:class => "form-control"} %>
<br />
<%= f.input :profile_name, :required => true, :autofocus => true, label: false, placeholder: "Bilbo18...", :input_html => {:class => "form-control"} %>
<br />
<%= f.input :email, :required => true, :autofocus => true, label: false, placeholder: "Email please...", :input_html => {:class => "form-control"} %>
<br />
<%= f.input :password, :required => true, label: false, placeholder: "Enter Password", :input_html => {:class => "form-control"} %>
<br />
<%= f.input :password_confirmation, :required => true, label: false, placeholder: "Confirm Password!", :input_html => {:class => "form-control"} %>
<br />
</div>
<div class="form-actions">
<%= f.button :submit, "Sign up", :class => 'btn-primary' %>
</div>
</div>
</div>
<% end %>
<div class="span3">
<h2 style="color:white;">Link Up</h2>
<%= link_to "Sign in with Facebook", user_omniauth_authorize_path(:facebook) %>
</div>
</div>
用户架构:
create_table "users", force: true do |t|
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.integer "sign_in_count", default: 0
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.datetime "created_at"
t.datetime "updated_at"
t.string "rank", default: "0"
t.string "first_name"
t.string "last_name"
t.string "profile_name"
t.boolean "admin", default: false
t.integer "sash_id"
t.integer "level", default: 0
t.string "provider"
t.string "uid"
t.string "name"
t.string "confirmation_token"
t.datetime "confirmed_at"
t.datetime "confirmation_sent_at"
end
add_index "users", ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true, using: :btree
add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree
add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree
end