ROR - 路由规则不起作用

时间:2015-09-23 19:47:39

标签: ruby-on-rails routing

我是ROR的新手,我正在尝试向我的控制器添加一个新方法,但我无法解决它。以下是控制器中的新方法:

    def bulkItemsUpload
    respond_to do |format|
      options = { col_sep: ',', converters: :numeric, headers: true }
      array = []
      CSV.foreach(params[:file].path, options) do |row|
        array.push(row.to_hash)
      end
      logger.debug "Parsed items: #{array.inspect}"
      format.html { redirect_to companies_path }
      format.js  { render json: JSON.pretty_generate(array) }
    end
  end

以下是控制器的现有路线:

resources :projects, except: :show do
    collection do
      get :search
      get :look_for_name
      # post :bulkItemsUpload
    end

    member do
      patch "/archive/:archive", constraints: {archive: /true|false/}, action: :archive, as: :archive
    end
    match "/timesheet", to: "timesheets#show", via: [:get, :post], as: :timesheet
    match "/items", to: "items#show", via: [:get, :post], as: :items
    match "/search_reports", to: "reports#index", via: [:post], as: :search_reports

    resources :reports, except: :destroy
    resource :email_permissions, only: [:new, :create]

    resources :project_workers, only: [:destroy, :update] do      
      resources :worked_hours, only: [:update]
    end
    resources :project_items, only: [:destroy, :update] do
      resources :used_items, only: [:update]
    end
  end

我在路径文件中添加了bulkItemsUpload条目,但仍然无法解决它。知道我做错了吗?

1 个答案:

答案 0 :(得分:1)

首先。你评论了你的路线。您应该删除#符号。

二。在ruby方法(action)中应该有这样的名字:

def bulk_items_upload
...
end

如果您从Rails开始,我建议您在浏览器中固定一些页面:

Ruby style guide

Rails style guide

对你有用。