Ruby on rails Rails 4-未调用控制器

Ruby on rails Rails 4-未调用控制器,ruby-on-rails,ruby-on-rails-4,Ruby On Rails,Ruby On Rails 4,我可以点击importers\u vendor\u ledger操作,但我似乎无法通过uploaders\upload\u file中的redirect\u-based\u-on(arg)方法点击importer\u-chart\u-of-accounts操作。请帮忙 注意:我遗漏了一些我认为没有必要看到的代码 我的代码: routes.rb resources :uploaders do collection { post :upload_file } end resources :i

我可以点击
importers\u vendor\u ledger
操作,但我似乎无法通过
uploaders\upload\u file
中的
redirect\u-based\u-on(arg)
方法点击
importer\u-chart\u-of-accounts
操作。请帮忙

注意:我遗漏了一些我认为没有必要看到的代码

我的代码:

routes.rb

resources :uploaders do
   collection { post :upload_file }
end

resources :importers do
   collection { post :import_vendor_ledger, :import_chart_of_accounts }
end
index.html.haml

#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'
上传程序\u 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
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
class UploadersController
导入程序u 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
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
类导入器控制器
编辑#1:即使我在uploaders#upload(上传)文件
中显式调用redirect(重定向)导入#账户图表(导入#账户图表)路径


编辑#2:在检查更多信息后,似乎正在点击
进口商#导入#账户图表
操作,但没有调用该操作中的任何函数

将您的路径更改为以下内容:

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

编辑:由于您正在重定向到这两条路径,我相信,您需要这些路径来获取路径。由于
redirect\u to
发出了一个
301请求
,该请求将成为GET请求。

当账户是
chart\u账户
时,您会得到什么响应?有错误吗?