Ruby 有人知道我怎么做吗;如果;在轨道上?

Ruby 有人知道我怎么做吗;如果;在轨道上?,ruby,Ruby,我一直在开发一个小应用程序,在创建新帖子时,我希望我的应用程序检查数据库中的某些文本值,特别是“已完成” 到目前为止,我想出了这个 @job = current_user.Jobs.where(:all, :project_status => "completed") if @job.exists? do something else send an error end 这是完全错误的,在读了一点之后,通过几个例子,我认为下面做了同样的事情 @job = current_us

我一直在开发一个小应用程序,在创建新帖子时,我希望我的应用程序检查数据库中的某些文本值,特别是“已完成”

到目前为止,我想出了这个

@job = current_user.Jobs.where(:all, :project_status => "completed")
if @job.exists?
   do something
else
   send an error
end
这是完全错误的,在读了一点之后,通过几个例子,我认为下面做了同样的事情

@job = current_user.Jobs.exists?(:conditions = {:project_status => "completed"})
但在我的研究中,我还没有发现一个例子,上面的这一行进入了“如果”状态,我只是这样做了吗

@job = current_user.Jobs.exists?(:conditions = {:project_status => "completed"})
     if @job
        do something here
     else
        do something else here
     end

那会更短、更干净、更正确吗?

我不确定这一栏里还有什么。Include可能不如计算字符串快

if @job.project_status.include?("completed")
 #something here 
else
 #nothing
end
if @job.project_status == 'completed'
 #something here 
end
这可能会比包含更快?如果什么也不会发生,你也不需要有一个else。

定义“不成功”;
if
if
有什么