1

resque gem とbiorubyでバックグラウンド処理を使用していますが、処理は正しく機能しています。ただし、「テンプレートがありません」というエラーが発生します。アクションがテンプレートをロードしようとしているようです。

Missing template cosmics/start_batch, application/start_batch with {:locale=>[:en],
:formats=>[:html], :handlers=>[:erb, :builder, :coffee]}. 

テンプレートをロードしたくない: バックグラウンド プロセスが外部ソースからデータを取得し、データベース テーブルを更新します (これはすべて機能しています)。

コードはボタンによってトリガーされます。

<%= link_to 'Process', start_batch_path, :class =>"btn btn-primary" %>

config/routes.rb

match '/cosmics/start_batch', :to => 'cosmics#start_batch', :as => 'start_batch'
resources :batches do
  resources :batch_details
end

cosmics_controller.rb

def start_batch
  @batch = Batch.create!(:status => 'created',:status_timestamp => Time.now)
  @cosmics = Cosmic.find(:all, :conditions => {:selected => true}).each do |cosmic|
    @batch_detail = BatchDetail.create!(:batch_id => @batch.id, :cosmic_mut_id => cosmic.cosmic_mut_id)
    @batch_detail.save
    cosmic.selected = false
    cosmic.save
  end
  Resque.enqueue(UcscQuery,@batch.id)
end

workers/ucsc_query.rb (reqsue ワーカー クラス)

class UcscQuery
  require 'bio-ucsc'
  include Bio 

@queue = :ucsc_queue

def self.perform(batch_id)
  Ucsc::Hg19.connect
  @batch_detail = BatchDetail.find(:all, :conditions => {:batch_id => batch_id}).each do |batch_detail|
    ucsc_cosmic = Ucsc::Hg19::Cosmic.find_by_name(batch_detail.cosmic_mut_id)
    if ucsc_cosmic
      batch_detail.bin = ucsc_cosmic.bin
      batch_detail.chrom = ucsc_cosmic.chrom
      batch_detail.chrom_start = ucsc_cosmic.chromStart
      batch_detail.chrom_end = ucsc_cosmic.chromEnd
      batch_detail.status = 'processed'
      batch_detail.save
    end
  end
  Batch.update(batch_id, :status => 'located')
end
end

Rails が cosmics/start_batch テンプレートを読み込もうとするのを防ぐにはどうすればよいですか? リファクタリングのヒントもいただければ幸いです。

4

2 に答える 2

2

renderコントローラ メソッドに or 命令がない場合redirect、Rails はメソッドと同じ名前のビューを探します。この動作を変更するには、メソッドrender :nothing => trueの最後に追加します。start_batch

これにより、ユーザーがProcessリンクをクリックすると、空白のページが表示されます。それは確かにあなたが望むものではありません。:remote => true オプションを使用しlink_toて、ユーザーが現在のページにとどまるようにすることができます。

<%= link_to 'Process', start_batch_path, {:remote => true}, {id: 'process_btn', :class => "btn btn-primary"} %>    

最後に、JavaScript を使用して、ボタンをクリックしたときに「何か」が発生したことをユーザーに示します。例:

$('#process_btn').on('click', function() { alert('Batch process started'); };
于 2013-06-10T11:29:36.363 に答える
1

次のように入力するだけです。

render :nothing => true

あなたの行動で。リンクをリモートに変更することもお勧めします

<%= link_to 'Process', start_batch_path, :class =>"btn btn-primary", :remote => true %>

そうしないと、クリックした後に空白のページが表示されます。

于 2013-06-10T11:30:02.760 に答える