sergserg
sergserg

Reputation: 22264

Trouble with ruby on rails routes with two word controller name

I wanted to create a controller called Database Importer.

Here's what I ran:

rails generate controller database_importer index

Which generated:

class DatabaseImporterController < ApplicationController
  def index
  end

  def import
    # to do.
    # Receive the uploaded CSV file and import to the database.
    CSV.foreach("parse.csv") do |row|

    end
  end
end

When I visit http://0.0.0.0:3000/database_importer/index I get:

Routing Error

No route matches {:action=>"import", :controller=>"database_importer"}
Try running rake routes for more information on available routes.

Here is my relevant route:

get 'database_importer/index'

Why is the routing engine trying to push me towards the import action method?

When I try to change the route to reflect the actual controller name (it doesn't have the underscore), I get:

get 'databaseimporter/index'

Routing Error

uninitialized constant DatabaseimporterController
Try running rake routes for more information on available routes.

Upvotes: 2

Views: 2401

Answers (1)

Cody Caughlan
Cody Caughlan

Reputation: 32758

Do you also have a route defined like:

post 'database_importer/import'

I think the form action is what is failing when Rails is trying to generate the route for the form.

Upvotes: 2

Related Questions