想创建一个注册页面,注册需要的信息是 studentsid name email。bundle exec rake db:migrate 是发生问题
C:\Users\pcjjdy\Desktop\final project>bundle exec rake db:migrate
== AddIndexToUsersEmail: migrating ===========================================
-- add_index(:studentsid, :users, :email, {:unique=>true})
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:
wrong number of arguments (4 for 2..3)C:/Users/pcjjdy/Desktop/final project/db/m
igrate/20141022140717_add_index_to_users_email.rb:3:in `change'
C:in `migrate'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
db\migrate\20141022140717_add_index_to_users_email 代码如下
class AddIndexToUsersEmail < ActiveRecord::Migration
def change
add_index :studentsid, :users, :email, unique: true
end
end
db\migrate\20141130233939_create_users.rb 代码如下
class CreateUsers < ActiveRecord::Migration
def change
create_table :users do |t|
t.string :studentsid
t.string :name
t.string :email
t.timestamps
end
end
end
app\controllers\users_controller.rb 代码如下
class UsersController < ApplicationController
def show
@user = User.find(params[:id])
@microposts = @user.microposts
end
def new
@user = User.new
end
def create
secure_params = params.require(:user).permit(:studentsid, :name, :email,
:password, :password_confirmation)
@user = User.new(secure_params)
if @user.save
sign_in @user
flash[:success] = "Thank you for your registing!"
redirect_to @user
else
render 'new'
end
end
end