2015-05-21 69 views
1

:fname,:lname,:email,:mob,:gender_male,:gender_female,:country,:state,:郊區,:郵政,: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

邪惡的寶石已經由Ryan貝茨 http://railscasts.com/episodes/346這裏解釋-wizard-形式與 - 邪惡?鑑於= asciicast –

+0

請不要投我失望,這是我的第一個問題,並給出一些建議 –

+0

但他已經用ATTR未在軌道4,5 –

回答

0

編輯在user_controller.rb

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 

創建這將在數據庫中添加數據

+0

謝謝@Nitin Rajan ...它工作正常,但如何給驗證? –

+1

你可以使用gem'client_side_validations'來驗證 –

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 

而且儘量保持合適的名字字段,它會幫助你在長期運行。

+0

是的,現在錯誤不會來...但數據庫中的密碼字段爲空 –

+0

已更新,請檢查並替換代碼。 –

+0

也請考慮接受答案,如果它幫助你解決你的問題 –