无法向设计用户添加其他字段

时间:2016-08-14 17:32:01

标签: ruby-on-rails ruby ruby-on-rails-4 devise

正如标题所说,当我尝试向用户添加列时,我得到一个错误的未定义方法。

Ruby - 2.3 Rails - 4.2.5我使用c9作为云IDE。

我首先要做的是:" rails g migration AddFieldsToUsers"

然后我将其添加到DB中:

class AddFieldsToUsers < ActiveRecord::Migration
def change
add_column :users, :username, :string
add_column :users, :current_goals, :text
add_column :users, :achieved_goals, :text
end
end

我运行&#34; rake db:migrate&#34;

我创建了registration_controller.rb

class RegistrationsController < Devise::RegistrationsController

private

def sign_up_params
params.require(:user).permit(:first_name, :last_name, :email, :password, :password_confirmation)
end

def account_update_params
params.require(:user).permit(:current_goals, :first_name, :last_name, :email, :password, :password_confirmation, :current_password)
end
end

我将其添加到路线中:

devise_for :users, :controllers => { registrations: 'registrations' }

我将相应的字段添加到视图中,当我打开&#34; users / edit&#34;页面,我收到此错误:

undefined method `current_goals' for #User:0x00000004e892f8
Did you mean? current_password

我在两个项目中尝试了两次,我也遇到了同样的错误。

0 个答案:

没有答案