0
問題:我想打password
& password_confirmation
領域validates presence:true
爲create
行動和update
行動設計CRUD驗證
guest.rb沒有驗證:
class Guest < ActiveRecord::Base
devise :database_authenticatable, :recoverable, :rememberable, :trackable
validates :email, presence: true
end
我guests_controller.rb:
class GuestsController < ApplicationController
before_action :set_guest, only: [:show, :edit, :update]
def index
@guests = Guest.all
end
def show
@guest = Guest.find(params[:id])
end
def new
@guest = Guest.new
end
def edit
@guest = Guest.find(params[:id])
end
def create
respond_to do |format|
format.html do
@guest = Guest.new(guest_params)
if @guest.save
redirect_to guests_path, notice: 'Client was successfully created.'
else
render :new
end
end
end
end
def update
@guest = Guest.find(params[:id])
if @guest.update_attributes(guest_params)
sign_in(@guest, :bypass => true) if @guest == current_guest
redirect_to guests_path, notice: 'Client was successfully updated.'
else
render :edit
end
end
如果我把validates :password, presence: true
,它影響一切,而我需要它僅適用於create
謝謝,我會 –