0

フィールド"name"をDeviseに追加しようとしていますが、新しいユーザーをサインアップすると、送信を押すと壊れます。

実行することを確認しrake db:migrate、サーバーを再起動しましたが、次のエラーが発生します。

ActiveRecord::StatementInvalid in Devise::RegistrationsController#create

NoMethodError: nil:NilClass の未定義のメソッド `name': INSERT INTO "users" ("created_at", "current_sign_in_at", "current_sign_in_ip", "email", "encrypted_pa​​ssword", "last_sign_in_at", "last_sign_in_ip", "name", "pic_file_name"、"remember_created_at"、"reset_password_sent_at"、"reset_password_token"、"sign_in_count"、"title"、"updated_at") 値 ($1、$2、$3、$4、$5、$6、$7、$8、$9、$10、 $11、$12、$13、$14、$15) 「ID」を返す

ユーザー クラス

  class User < ActiveRecord::Base
  has_and_belongs_to_many :roles

    devise :database_authenticatable, :registerable,
     :recoverable, :rememberable, :trackable, :validatable

    attr_accessible :email, :password, :password_confirmation, :remember_me, :role_ids, :name, :title, :pic_file_name
    has_one :picture, :dependent => :destroy
    accepts_nested_attributes_for :picture, :allow_destroy => true
    has_many :comments, :dependent => :destroy
    has_many :discussions, :dependent => :destroy



    def role?(role)
      roles.map(&:name).include? role.to_s
    end

  end

スキーマ

  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",                             :null => false
t.datetime "updated_at",                             :null => false
t.string   "name"
t.string   "title"
t.string   "pic_file_name"
  end

新規登録ビュー

<%= simple_form_for(resource, :as => resource_name, :html => { :multipart => true }, :html => { :class => 'form-horizontal' }, :url => registration_path(resource_name)) do |f| %>
  <%= f.error_notification %>
  <div class="row">
    <div class="span12 rounded-corners shadow inputs registration">
      <div class="row">
        <div class="span6">
          <h1>Join the Club</h1>
            <%= f.input :email, :required => true, :autofocus => true, :input_html => { :class => "span4" } %>
            <%= f.input :password, :required => true, :input_html => { :class => "span4" } %>
            <%= f.input :password_confirmation, :required => true, :input_html => { :class => "span4" } %>
            <%= f.input :name, :required => true, :input_html => { :class => "span4" } %>

            <%= f.input :title, :required => true, :input_html => { :class => "span4" } %>
            <%= f.input :pic_file_name, :as => :file, :label => "Upload Profile Picture", :required => true %>
        </div>
        <div class="span6 .hidden-phone ">
          <%= image_tag "signup.png", :class => "rounded-corners shadow signup_pic" %>
        </div>
      </div>




      <div class="row">
        <div class="signup_actions span3">
          <%= f.button :submit, "Sign up", :class => 'btn-warning btn-large' %></br >
          <%= render "links" %>
        </div>
      </div>

    <% end %>

  </div>

4

1 に答える 1

0

attr_accessible:ユーザークラスの後に名前を付けます。

于 2012-07-30T10:15:19.767 に答える