我一直在研究一个小应用程序,并在创建新帖子的同时,希望我的应用程序检查数据库中是否存在特定文本值,特别是查找“已完成”。任何人都知道我可以做一个“如果”在铁轨?
到目前为止我想出了这个;
@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"})
,但我没有找到我的研究一个例子,其中上述线路进入“if”条件,我只是做;
@job = current_user.Jobs.exists?(:conditions = {:project_status => "completed"})
if @job
do something here
else
do something else here
end
会更短,更清洁和正确吗?
定义“不成功”; 'if'是'if'。什么是'拥有'? –