Wednesday, 18 September 2013

Invalid route name: 'users/:columnname_index' - Can't rollback, change column name, nor display some pages

Invalid route name: 'users/:columnname_index' - Can't rollback, change
column name, nor display some pages

I created a migration to add a Urlname column to Users table. Then I added
an index to the migration. Here's the resulting migration:
class AddUrlnameToUsers < ActiveRecord::Migration
def change
add_column :users, :urlname, :string
add_index :users, :urlname, :unique => true
end
end
Then I used rake db:migrate.
schema.rb contains the 'urlname' column & says it has a unique index.
However, certain pages on my site have errors: Invalid route name:
'users/:urlname_index'.
Fine, I don't want to call it 'urlname' anyway. I want to call it
'permalink'. But now I can't generate a FixColumnName migration, a
RemoveUrlNameFromUsers, nor can I rollback - same "Invalid route name:
'users/:urlname_index'" error for all three.
So I removed add_index :users, :urlname, :unique => true from the
migration file, even though I had already migrated it. That didn't help.
My routes.rb contains
Crowdpublishtv::Application.routes.draw do
devise_for :users
resources :users
#resources 'users/:urlname', :to => 'User#booklist'
#match 'users/:urlname_index', :to => 'users#show'
devise_for :users
authenticated :user do
root :to => "users#booklist"
end
get "attachments/show"
resources :users do
resources :books
end
devise_for :users
resources :users do
member do
get 'booklist', 'blog', 'profileinfo', 'readerprofileinfo',
'orgprofileinfo'
end
end
end
I tried commenting out & uncommenting out the lines that are marked with
#. Didn't help.
Here's the relevant db:migrate status:
Status Migration ID Migration Name
--------------------------------------------------
up 20130319002105 Create users
up 20130328235904 ********** NO FILE **********
up 20130703205730 Add devise to users
up 20130911002912 Add bookfiles to users
up 20130917143106 Add urlname to users
The *NO FILE* was something I thought I had rolled back... But since it
was long before 'Add urlname to users,' I'm pretty sure it's irrelevant.
Any insight as to what is incorrect? I'm on rails 3.1.0, ruby 1.9.2, with
sqlite3, if that matters.

No comments:

Post a Comment