簡體   English   中英

無法解析Ruby和Rails中的csv文件

[英]Unable to parse the csv file in ruby and rails

我是Rails平台上的ruby的新手,我只是嘗試了一些示例代碼。 我正在嘗試運行此示例http://goodbadtech.com/2009/05/13/ruby-on-rails-import-csv-data-into-database/我遵循了所有說明,但出現此錯誤

ActionController :: RoutingError(未初始化的常量CsvImportController):

請幫助我消除這個錯誤。

這是我的Routes.rb

Imports::Application.routes.draw do
  # The priority is based upon order of creation:
  # first created -> highest priority.
 get "csv_imports/csv_view"
#map.resources :imports
#map.import_proc '/import/proc/:id', :controller => "imports", :action => "proc_csv"
  # Sample of regular route:
  #   match 'products/:id' => 'catalog#view'
  # Keep in mind you can assign values other than :controller and :action

  # Sample of named route:
  #   match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
  # This route can be invoked with purchase_url(:id => product.id)

    resources :imports
    import_proc '/import/proc/:id', :controller => "csv_imports", :action => "pro_csv"
    end 

  # Sample resource route (maps HTTP verbs to controller actions automatically):
  #   resources :products

  # Sample resource route with options:
  #   resources :products do
  #     member do
  #       get 'short'
  #       post 'toggle'
  #     end
  #
  #     collection do
  #       get 'sold'
  #     end
  #   end

  # Sample resource route with sub-resources:
  #   resources :products do
  #     resources :comments, :sales
  #     resource :seller
  #   end

  # Sample resource route with more complex sub-resources
  #   resources :products do
  #     resources :comments
  #     resources :sales do
  #       get 'recent', :on => :collection
  #     end
  #   end

  # Sample resource route within a namespace:
  #   namespace :admin do
  #     # Directs /admin/products/* to Admin::ProductsController
  #     # (app/controllers/admin/products_controller.rb)
  #     resources :products
  #   end

  # You can have the root of your site routed with "root"
  # just remember to delete public/index.html.
  # root :to => 'csv_imports#csv_view'

  # See how all your routes lay out with "rake routes"

  # This is a legacy wild controller route that's not recommended for RESTful applications.
  # Note: This route will make all actions in every controller accessible via GET requests.
  # match ':controller(/:action(/:id(.:format)))'

包含類CsvImportsController文件應命名為csv_imports_controller 我相信那是錯誤。 在路由中,您應該

resources :csv_imports

[EDIT]另一方面,如果您的控制器名為ImportsController ,放置在imports_controller.rb ,那么在路由中,您應該

resources :imports

Rails會自動嘗試根據名稱將事物捆綁在一起。 如果您正確地遵循它們,這將使事情變得容易。 因此resources :imports將假設有一個名為ImportsController的控制器,可以在app/controllers/imports_controller.rb 最佳做法是調用相關模型Import ,該模型可以在app/models/import.rb

希望這可以幫助。

(還要注意,您提到的博客文章是針對Rails 2而非Rails 3的)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM