开发者

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜