:fname,:lname,:email,:mob,:gender_male,:gender_female,:country,:state,:suburb,:postal,:add无法保存在数据库中....请帮助和验证也是
这是我的用户控制器
def new
@user = User.new
end
def create
@user = User.new(params[:id])
if @user.save
session[:user_id]= @user.id
redirect_to user_steps_path
else
render :new
end
end
private
def user_params
params.require(:user).permit( :fname, :lname, :email, :mob, :gender_male, :gender_female, :country, :state, :suburb, :postal ,:add, :cmpyname, :abnacn, :cmpyadd, :cmpydet,:cash, :paypal,:bsb,:usrname, :password, :password_confirmation, :selcat, :protit, :prodes)
end
这是我的user_steps控制器
include Wicked::Wizard
steps :business, :login, :payment
def show
@user = current_user
render_wizard
end
def update
@user = current_user
if @user.update_attributes(user_params)
render_wizard @user
end
end
private
def user_params
params.require(:user).permit( :fname, :lname, :email, :mob, :gender_male, :gender_female, :country, :state, :suburb, :postal ,:add, :cmpyname, :abnacn, :cmpyadd, :cmpydet,:cash, :paypal,:bsb,:usrname, :password, :password_confirmation, :selcat, :protit, :prodes)
end
我的迁移表
class CreateUsers < ActiveRecord::Migration
def change
create_table :users do |t|
t.string :fname
t.string :lname
t.string :email
t.string :mob
t.string :gender_male
t.string :gender_female
t.string :country
t.string :state
t.string :suburb
t.string :postal
t.string :add
t.string :cmpyname
t.string :abnacn
t.string :cmpyadd
t.string :cmpydet
t.string :cash
t.string :paypal
t.string :bsb
t.string :usrname
t.string :password_hash
t.string :password_salt
t.string :selcat
t.string :protit
t.string :prodes
t.timestamps
end
end
end
答案 0 :(得分:1)
在迁移过程中,您已将password_hash和password_salt作为字段,并在控制器中仅提及密码。更新控制器中的user_params方法,如下所示 -
def user_params
params.require(:user).permit( :fname, :lname, :email, :mob,:password_hash,:password_salt, :gender_male, :gender_female, :country, :state, :suburb, :postal ,:add, :cmpyname, :abnacn, :cmpyadd, :cmpydet,:cash, :paypal,:bsb,:usrname, :selcat, :protit, :prodes)
end
还要尝试为字段保留正确的名称,因为从长远来看它会帮助你。
答案 1 :(得分:0)
在user_controller.rb中编辑create
def create
@user = User.new(params[:id])
if @user.save
session[:user_id]= @user.id
@user.update_attributes(user_params )
redirect_to user_steps_path
else
render :new
end
end
这将在数据库中添加该数据