私はimporters#import_vendor_ledger
アクションを打つことができますが、uploaders#upload_file
のredirect_based_on(arg)
メソッドでimporters#import_chart_of_accounts
アクションを打つことはできません。助けてください!Rails 4 - コントローラが呼び出されていない
注:
index.html.hamlroutes.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_file
でredirect_to import_chart_of_accounts_importers_path
を呼び出す場合でも、それはまだimporters#import_chart_of_accounts
アクション
EDIT#2にヒットしません:続きを検査した後、それはそうですそのimporters#import_chart_of_accounts
アクションはヒットしましたが、アクション内のどの機能も呼び出されていません
アカウントが「chart_of_accounts」の場合、どのような応答が得られますか?任意のエラー? – Sajan