Reputation: 4649
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)))'
Upvotes: 0
Views: 495
Reputation: 50057
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)
Upvotes: 4