Noob help to reformat if's to case Rails
Hi can anyone help me refactor this code into case statements in Ruby
def can_save?
if signed_in?
@user.updating_password = false
return true 开发者_StackOverflow社区if @greeting.save & @user.save
elsif !guest_user? & @greeting.valid? & @user.valid?
sign_in(@user) if @greeting.save & @user.save
return true
elsif guest_user?
if !params[:user][:email].blank? & (@user.valid? & @greeting.valid?)
if (@greeting.save & @user.save)
sign_in(@user)
return true
end
elsif params[:user][:email].blank?
return true if @greeting.save
end
end
end
def can_save?
validation_check
if signed_in?
@user.updating_password = false
else
unless params[:user][:email].blank?
sign_in(@user)
end
end
end
private
def validation_check
if @user.valid? && @greeting.valid?
@user.save
@greeting.save
else
return
end
end
精彩评论