Ruby on rails 添加要设计的值名称时出错

Ruby on rails 添加要设计的值名称时出错,ruby-on-rails,ruby,ruby-on-rails-3,devise,Ruby On Rails,Ruby,Ruby On Rails 3,Devise,我在尝试添加要设计的值名称时遇到了一个错误,我认为所有人都做了所有的事情来让它工作,但它不工作 NoMethodError in Devise/registrations#new undefined method `name' for #<User:0x00000002e4e038> 至少在该迁移文件中,似乎缺少users表的name列 添加users表的name列 rails g migration AddNameToUsers 类AddNameToUsers

我在尝试添加要设计的值名称时遇到了一个错误,我认为所有人都做了所有的事情来让它工作,但它不工作

NoMethodError in Devise/registrations#new

undefined method `name' for #<User:0x00000002e4e038>

至少在该迁移文件中,似乎缺少users表的
name

添加users表的name列

rails g migration AddNameToUsers

类AddNameToUsers 运行
rake migrate

重新启动服务器只是为了安全


最后编辑。再也不会了

在设计迁移文件中,取消注释

t.string:确认\u令牌
t、 日期时间:已确认
t、 日期时间:确认发送至
t、 字符串:未确认的电子邮件#仅当使用可再确认
rake db:drop db:create db:migrate


重新启动服务器

至少在该迁移文件中,似乎缺少用户表的
name

添加users表的name列

rails g migration AddNameToUsers

类AddNameToUsers 运行
rake migrate

重新启动服务器只是为了安全


最后编辑。再也不会了

在设计迁移文件中,取消注释

t.string:确认\u令牌
t、 日期时间:已确认
t、 日期时间:确认发送至
t、 字符串:未确认的电子邮件#仅当使用可再确认
rake db:drop db:create db:migrate


重新启动服务器

是否可以显示添加了名称属性的迁移文件?是否可以显示添加了名称属性的迁移文件?仍然无法工作,它会给出相同的错误。我不知道该怎么办。。但无论如何,还是要感谢@dmtri.com尝试执行
rake migrate
并重新启动server@Maia,当然,将schema.rb发布为well@Zippie,只是一般的良好做法。这是我在1.x天内做Rails时的一个习惯。还取决于Rails和数据库的设置方式,需要显式重新启动。@Zippie我不反对Zippie。我想这也是工作的本质。人们问的许多神秘问题通过服务器重启或捆绑安装之类的方式神奇地解决了。所以我只是推荐它。仍然不起作用,它给了我同样的错误。我不知道该怎么办。。但无论如何,还是要感谢@dmtri.com尝试执行
rake migrate
并重新启动server@Maia,当然,将schema.rb发布为well@Zippie,只是一般的良好做法。这是我在1.x天内做Rails时的一个习惯。还取决于Rails和数据库的设置方式,需要显式重新启动。@Zippie我不反对Zippie。我想这也是工作的本质。人们问的许多神秘问题通过服务器重启或捆绑安装之类的方式神奇地解决了。所以我只是推荐它。
class User < ActiveRecord::Base

  include Gravtastic
  gravtastic :size => 165, :filetype => :png, :rating => 'R'

  # Include default devise modules. Others available are:
  # :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable, :confirmable

  validates :email, :username, :presence => true, :uniqueness => true

  # Setup accessible (or protected) attributes for your model
  attr_accessible :name, :username, :email, :password, :password_confirmation, :remember_me

  has_many :topics, :dependent => :destroy
  has_many :posts, :dependent => :destroy

  def admin?
    true if self.username == 'admin'
  end

end
<h2>Sign up</h2>

<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
  <%= devise_error_messages! %>

  <p><%= f.label :name %><br />
  <%= f.text_field :name %></p>

  <p><%= f.label :email %><br />
  <%= f.email_field :email %></p>

  <p><%= f.label :password %><br />
  <%= f.password_field :password %></p>

  <p><%= f.label :password_confirmation %><br />
  <%= f.password_field :password_confirmation %></p>

  <p><%= f.submit "Sign up" %></p>
<% end %>

<%= render :partial => "devise/shared/links" %>
div class="module" style="padding:15px 25px 0px 25px;">

  <div style="float:right; width:100%; padding-left:30px; border-left:1px solid #e2e2e2;">
    <%= form_for("user", :as => resource_name, :url => registration_path("user")) do |f| %>
      <%= devise_error_messages! %>
      <p>
     Nome: <br />
        <%= f.text_field :name, :style => "font-size:2.0em", :autocomplete => "off" %><br />
      </p>
      <p>
     Usuario: <br />
        <%= f.text_field :username, :style => "font-size:2.0em", :autocomplete => "off" %><br />
      </p>
      <p>
        Email: (apenas emails @usp.br sao aceitos) <br />
        <%= f.text_field :email, :style => "font-size:2.0em", :autocomplete => "off" %><br />
      </p>
      <p>
        Senha:<br />
        <%= f.password_field :password, :style => "font-size:2.0em", :autocomplete => "off" %><br />
      </p>
      <p>
        Confirmar senha:<br />
        <%= f.password_field :password_confirmation, :style => "font-size:2.0em", :autocomplete => "off" %><br />
      </p>
      <p><%= f.submit "Criar" %></p>
    <% end %>
  </div>
  <div class="clear"></div>
</div>
class DeviseCreateUsers < ActiveRecord::Migration
  def self.up
    create_table(:users) do |t|
      t.database_authenticatable :null => false
      t.recoverable
      t.rememberable
      t.trackable
      t.confirmable

      # t.encryptable
      # t.confirmable
      # t.lockable :lock_strategy => :failed_attempts, :unlock_strategy => :both
      # t.token_authenticatable


      t.timestamps
    end

    add_index :users, :email,                :unique => true
    add_index :users, :reset_password_token, :unique => true
    # add_index :users, :confirmation_token,   :unique => true
    # add_index :users, :unlock_token,         :unique => true
    # add_index :users, :authentication_token, :unique => true
  end

  def self.down
    drop_table :users
  end
end
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# Note that this schema.rb definition is the authoritative source for your
# database schema. If you need to create the application database on another
# system, you should be using db:schema:load, not running all the migrations
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
# you'll amass, the slower it'll run and the greater likelihood for issues).
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20131121000236) do

  create_table "categories", :force => true do |t|
    t.string   "title"
    t.boolean  "state",      :default => true
    t.integer  "position",   :default => 0
    t.datetime "created_at"
    t.datetime "updated_at"
  end

  create_table "forums", :force => true do |t|
    t.string   "title"
    t.text     "description"
    t.boolean  "state",        :default => true
    t.integer  "topics_count", :default => 0
    t.integer  "posts_count",  :default => 0
    t.integer  "position",     :default => 0
    t.integer  "category_id"
    t.datetime "created_at"
    t.datetime "updated_at"
  end

  create_table "posts", :force => true do |t|
    t.text     "body"
    t.integer  "forum_id"
    t.integer  "topic_id"
    t.integer  "user_id"
    t.datetime "created_at"
    t.datetime "updated_at"
  end

  create_table "topics", :force => true do |t|
    t.string   "title"
    t.integer  "hits",        :default => 0
    t.boolean  "sticky",      :default => false
    t.boolean  "locked",      :default => false
    t.integer  "posts_count"
    t.integer  "forum_id"
    t.integer  "user_id"
    t.datetime "created_at"
    t.datetime "updated_at"
  end

  create_table "users", :force => true do |t|
    t.string   "email",                                 :default => "", :null => false
    t.string   "encrypted_password",     :limit => 128, :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.string   "confirmation_token"
    t.datetime "confirmed_at"
    t.datetime "confirmation_sent_at"
    t.datetime "created_at"
    t.datetime "updated_at"
    t.integer  "topics_count",                          :default => 0
    t.integer  "posts_count",                           :default => 0
    t.string   "username"
  end

  add_index "users", ["email"], :name => "index_users_on_email", :unique => true
  add_index "users", ["reset_password_token"], :name => "index_users_on_reset_password_token", :unique => true

end