У меня ошибка при попытке добавить имя значения для разработки, я думаю, что все сделали все, чтобы заставить его работать, но он не работает.Ошибка при добавлении имен значений для разработки
NoMethodError in Devise/registrations#new
undefined method `name' for #<User:0x00000002e4e038>
Вот моя модель пользователя:
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>
Я уже tryied rake db: migrate, но это s до этого не решает мою проблему. Извините, я все еще ноб на рельсах.
EDIT: Вот мой миграции файла:
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
EDIT 2: Вот мой schema.rb
# 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
вы можете показать свой миграционный файл, в котором вы добавили имя атрибута? – Zippie
Отредактировано сейчас @Zippie – Maia