0

I am a newbie to the ruby on rails platform and I was just trying out couple of example codes. I was trying to run this example http://goodbadtech.com/2009/05/13/ruby-on-rails-import-csv-data-into-database/ I followed all the instructions but I am getting this error

ActionController::RoutingError (uninitialized constant CsvImportController):

Please help me to bash this error.

Here is my 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)))'
4
  • 2
    Rails is looking for a CsvImportController, but I suppose you called it CSVImportController. Rename it and your problem might go away. Commented Nov 9, 2011 at 6:15
  • @Wukerplank: Do u mean in routes.rb file? Commented Nov 9, 2011 at 6:24
  • 1
    No, I think this refers to the controller. Just look at the app/controllers/csv_import_controller.rb file. What's the name of the class? Commented Nov 9, 2011 at 8:08
  • @Wukerplank the name of the class is ImportController.The File name is imports_controller.rb Commented Nov 9, 2011 at 8:23

1 Answer 1

4

Your file, containing the class CsvImportsController should be named csv_imports_controller. I believe that is the error. In your routing, you should have

resources :csv_imports

[EDIT] On the other hand, if your controller is named ImportsController, placed in imports_controller.rb, then inside your routing, you should have

resources :imports

Rails automatically tries to tie things together based on the names. This is what makes things easy if you follow them correctly. So resources :imports will assume there is a controller called ImportsController, which can be found in app/controllers/imports_controller.rb. It is best practice to call the relevant model Import, to be found in app/models/import.rb.

Hope this helps.

(also note that the blog-post you mention is for Rails 2 and not Rails 3)

Sign up to request clarification or add additional context in comments.

8 Comments

Rails 2 and Rails 3 does it make much difference?
In this case: the generators have changed (use rails generator), the routing has changed (syntax is now much leaner), and in rails 3 you use gems instead of plugins (while they still work).
:I followed the instructions which u suggested, now I am getting another error "/home/jeevan/csv/config/routes.rb:1:in `<top (required)>': uninitialized constant Imports (NameError)"
Please show your routes file. Or check railscasts or the documentation
hey I have posted routes.rb. please to check and reply thanks a lot for helping
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.