2017-01-18 12 views
0

私はimporters#import_vendor_ledgerアクションを打つことができますが、uploaders#upload_fileredirect_based_on(arg)メソッドでimporters#import_chart_of_accountsアクションを打つことはできません。助けてください!Rails 4 - コントローラが呼び出されていない

注:

index.html.haml

routes.rbを

resources :uploaders do 
    collection { post :upload_file } 
end 

resources :importers do 
    collection { post :import_vendor_ledger, :import_chart_of_accounts } 
end 

:私は

私のコードを参照する必要があったとは思いませんでしたいくつかのコードを残し

#chart_of_accounts 
    = form_tag upload_file_uploaders_path, multipart: true do 
    = hidden_field_tag :account, "chart_of_accounts" 
    = file_field_tag :file 
    = submit_tag 'Upload Chart of Accounts' 

#vendor_ledger 
    = form_tag upload_file_uploaders_path, multipart: true do 
    = hidden_field_tag :account, "vendor_ledger" 
    = file_field_tag :file 
    = submit_tag 'Upload' 

uploaders_controller.rb

class UploadersController < ApplicationController 
    include Excel 

    def upload_file 
    uploaded_io = params[:file] 
    if uploaded_io.path.downcase.end_with?(xlsx_extension) 
     save_to_storage(uploaded_io) 
     flash[:success] = 'File uploaded successfully!' 
     redirect_based_on_(params) # this is where it should call the action 
    else 
     flash[:warning] = 'ERROR: The file you upload MUST be an ".xlsx" excel file!' 
     redirect_to root_url 
    end 
    end 

    private 

    def redirect_based_on_(_params) 
    case _params[:account] 
    when "vender_ledger" 
     redirect_to import_vendor_ledger_importers_path and return 
    when "chart_of_accounts" 
     redirect_to import_chart_of_accounts_importers_path and return 
    end 
    end 
end 

importers_controller.rb

class ImportersController < ApplicationController 
    include Excel 

    def index 
    end 

    def show 
    end 

    def import_vendor_ledger # I can hit this action 
    puts "hits vendor ledger import" 
    end 

    def import_chart_of_accounts # but I can't hit this action 
    puts "hits chart of accounts import" 
    end 

EDIT#1:私は明示的にuploaders#upload_fileredirect_to import_chart_of_accounts_importers_pathを呼び出す場合でも、それはまだimporters#import_chart_of_accountsアクション

EDIT#2にヒットしません:続きを検査した後、それはそうですそのimporters#import_chart_of_accountsアクションはヒットしましたが、アクション内のどの機能も呼び出されていません

+0

アカウントが「chart_of_accounts」の場合、どのような応答が得られますか?任意のエラー? – Sajan

答えて

1

あなたのルートを次のように変更してください:

resources :importers do 
    collection do 
    get :import_vendor_ledger 
    get :import_chart_of_accounts 
    end 
end 

EDIT:これらの2つのパスにリダイレクトされているので、これらのパスをGETルートにする必要があります。 redirect_to301 requestを発行します。これはGETリクエストになります。

+0

ありがとうございました! – wsgb

関連する問題