このレールコントローラのより良いループを構築する方法について考えていますか?このループを書くにはどうすればよいでしょうか?
私は時々論理ループを失うので、私はネアンデルタール語のコードに頼っています。
def index
@step1_status = current_user.steps.pluck(:step1).first
@step2_status = current_user.steps.pluck(:step2).first
@step3_status = current_user.steps.pluck(:step3).first
@step4_status = current_user.steps.pluck(:step4).first
@step5_status = current_user.steps.pluck(:step5).first
@step6_status = current_user.steps.pluck(:step6).first
@step7_status = current_user.steps.pluck(:step7).first
@step8_status = current_user.steps.pluck(:step8).first
@step9_status = current_user.steps.pluck(:step9).first
if @step9_status == true
@task = Task.limit(1).order('sort_id ASC').where.not(:sort_id => ['1', '2', '3', '4', '5', '6', '7', '8', '9'])
elsif @step8_status == true
@task = Task.limit(1).order('sort_id ASC').where.not(:sort_id => ['1', '2', '3', '4', '5', '6', '7', '8'])
elsif @step7_status == true
@task = Task.limit(1).order('sort_id ASC').where.not(:sort_id => ['1', '2', '3', '4', '5', '6', '7'])
elsif @step6_status == true
@task = Task.limit(1).order('sort_id ASC').where.not(:sort_id => ['1', '2', '3', '4', '5', '6'])
elsif @step5_status == true
@task = Task.limit(1).order('sort_id ASC').where.not(:sort_id => ['1', '2', '3', '4', '5'])
elsif @step4_status == true
@task = Task.limit(1).order('sort_id ASC').where.not(:sort_id => ['1', '2', '3', '4'])
elsif @step3_status == true
@task = Task.limit(1).order('sort_id ASC').where.not(:sort_id => ['1', '2', '3'])
elsif @step2_status == true
@task = Task.limit(1).order('sort_id ASC').where.not(:sort_id => ['1', '2'])
elsif @step1_status == true
@task = Task.limit(1).order('sort_id ASC').where.not(:sort_id => '1')
else
@task = Task.limit(1).order('sort_id ASC')
end
end
ありがとうございました!
異なる行を得るために、同じ行を9回(9回のDBコール!)実行するのは何ですか?そしてなぜあなたはセパレートテーブルに 'stepN'の怪物を作る(つまり正規化する)のではなく、実際にステップ名をデータとして使用できるようにしたのですが、" neandertal code "を使うのではなく、これは設計によって意図的に行われているのですか、これは設計上の見落としですか? –
何のループ?ここにループはありません。 –
母、私は知っています。それはたわごとだ。 – Jordan