Neil
Neil

Reputation: 5178

Routing Error Uninitialized Constant Rails

When I click this link on a page <%= link_to 'Submit an Application', new_s_n_d_sub_path %> it is giving me the following error:

Routing Error uninitialized constant SNDSubsController

This is a simple thing, but I'm not sure where I'm messing up.

I have the s_n_d_subs_controller.rb file with:

class SNDSubsController < ApplicationController

def new
   ...
end

Within views I have the file: s_n_d_subs/new.html.erb

Within routes I have resources :s_n_d_subs

Rake Routes:

    s_n_d_subs GET    /s_n_d_subs(.:format)          s_n_d_subs#index
               POST   /s_n_d_subs(.:format)          s_n_d_subs#create
 new_s_n_d_sub GET    /s_n_d_subs/new(.:format)      s_n_d_subs#new
edit_s_n_d_sub GET    /s_n_d_subs/:id/edit(.:format) s_n_d_subs#edit
     s_n_d_sub GET    /s_n_d_subs/:id(.:format)      s_n_d_subs#show
               PATCH  /s_n_d_subs/:id(.:format)      s_n_d_subs#update
               PUT    /s_n_d_subs/:id(.:format)      s_n_d_subs#update
               DELETE /s_n_d_subs/:id(.:format)      s_n_d_subs#destroy
          root GET    /                              welcome#index

What am I missing?

Upvotes: 0

Views: 241

Answers (2)

Neil
Neil

Reputation: 5178

I ended up just changing the names of my models and regenerating the controllers and views. I think what was throwing me off was I named my models with single letters representing words: s_n_d_subs which was causing me confusion when I generated controllers and views. So what I did was changed my model names so each part separated by an underline had at least two letters: ex: surv_dev.rb. This way when I generated controllers and routes it all worked just fine.

Upvotes: 1

Ajay
Ajay

Reputation: 4251

Your SNDSubs Is treated as a constant rather than a class. :( Try this :

#app/controllers/sn_d_subs_controller.rb

    class SnDSubsController
      def new
      end
    end

In your routes: 
resources :sn_d_subs

Upvotes: 0

Related Questions