0

我正在尝试将该字段添加"name"到设计中,但是当我注册一个新用户时,它会在我推送提交时中断。

我已确保运行rake db:migrate并重新启动服务器,但出现此错误

设计中的 ActiveRecord::StatementInvalid::RegistrationsController#create

NoMethodError:nil 的未定义方法“名称”:NilClass:插入“用户”(“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 回答