Newbie RESTful routing problem, please help!

Hello, on my last post a few weeks ago, all who replied seemed to agree that the problem I was having was in my routing configuration. I decided to read up a bit on rails routing using this article:

I decided to try what the article calls RESTful routing. So I set my model:

class Receta < ActiveRecord::Base end

I set up my controller:

class RecetaController < ApplicationController   def index

  end

end

And I set up my view (which I generated along with my controller:

<h1>Receta#index</h1> <p>Find me in app/views/receta/index.html.erb</p>

I then set up my routing in routes.rb as follows:

map.resources :recetas

I got an error with the following full trace:

C:/jruby/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:443:in `load_missing_constant' C:/jruby/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:80:in `const_missing_with_dependencies' C:/jruby/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:92:in `const_missing' C:/jruby/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/inflector.rb:361:in `constantize' C:/jruby/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/inflector.rb:360:in `each' C:/jruby/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/inflector.rb:360:in `constantize' C:/jruby/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/core_ext/string/inflections.rb:162:in `constantize' C:/jruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/routing/route_set.rb:443:in `recognize' C:/jruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/routing/route_set.rb:436:in `call' C:/jruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/dispatcher.rb:87:in `dispatch' C:/jruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/dispatcher.rb:121:in `_call' C:/jruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/dispatcher.rb:130:in `build_middleware_stack' C:/jruby/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/query_cache.rb:29:in `call' C:/jruby/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/query_cache.rb:29:in `call' C:/jruby/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapters/abstract/query_cache.rb:34:in `cache' C:/jruby/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/query_cache.rb:9:in `cache' C:/jruby/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/query_cache.rb:28:in `call' C:/jruby/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:361:in `call' C:/jruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/string_coercion.rb:25:in `call' C:/jruby/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/head.rb:9:in `call' C:/jruby/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/methodoverride.rb:24:in `call' C:/jruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/params_parser.rb:15:in `call' C:/jruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/session/cookie_store.rb:93:in `call' C:/jruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/failsafe.rb:26:in `call' C:/jruby/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/lock.rb:11:in `call' C:/jruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/dispatcher.rb:114:in `call' C:/jruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/reloader.rb:34:in `run' C:/jruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/dispatcher.rb:108:in `call' C:/jruby/lib/ruby/gems/1.8/gems/glassfish-1.0.2-universal-java/lib/rack/adapter/rails.rb:133:in `call' C:/jruby/lib/ruby/gems/1.8/gems/glassfish-1.0.2-universal-java/lib/rack/handler/grizzly.rb:55:in `call'

I then tried setting up my routing like this:

map.resources :receta

  And it worked. Can someone please clarify why with :recetas it didn't work? What difference does it make to declare a resource with an "s" at the end. Any info will be greatly appreciated. Thanks in advance.

Note: I removed the default routes for both attempts.

The convention is that controllers are plural, so instead of...

class RecetaController < ApplicationController

you should have...

class RecetasController < ApplicationController

note the plural form of Recetas

your controller should be:

class RecetasController < ApplicationController def index end end

not:

class RecetaController < ApplicationController

在2010-02-17 11:11:56,"tuti plain" <lists@ruby-forum.com> 写道:
>Hello, on my last post a few weeks ago, all who replied seemed to agree
>that the problem I was having was in my routing configuration.  I
>decided to read up a bit on rails routing using this article:
>http://guides.rails.info/routing.html
>
>I decided to try what the article calls RESTful routing.  So I set my
>model:
>
>class Receta < ActiveRecord::Base
>end
>
>I set up my controller:
>
>class RecetaController < ApplicationController
>  def index
>
>  end
>
>end
>
>And I set up my view (which I generated along with my controller:
>
><h1>Receta#index</h1>
><p>Find me in app/views/receta/index.html.erb</p>
>
>I then set up my routing in routes.rb as follows:
>
> map.resources :recetas
>
>I got an error with the following full trace:
>
>C:/jruby/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:443:in
>`load_missing_constant'
>C:/jruby/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:80:in
>`const_missing_with_dependencies'
>C:/jruby/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:92:in
>`const_missing'
>C:/jruby/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/inflector.rb:361:in
>`constantize'
>C:/jruby/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/inflector.rb:360:in
>`each'
>C:/jruby/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/inflector.rb:360:in
>`constantize'
>C:/jruby/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/core_ext/string/inflections.rb:162:in
>`constantize'
>C:/jruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/routing/route_set.rb:443:in
>`recognize'
>C:/jruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/routing/route_set.rb:436:in
>`call'
>C:/jruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/dispatcher.rb:87:in
>`dispatch'
>C:/jruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/dispatcher.rb:121:in
>`_call'
>C:/jruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/dispatcher.rb:130:in
>`build_middleware_stack'
>C:/jruby/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/query_cache.rb:29:in
>`call'
>C:/jruby/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/query_cache.rb:29:in
>`call'
>C:/jruby/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapters/abstract/query_cache.rb:34:in
>`cache'
>C:/jruby/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/query_cache.rb:9:in
>`cache'
>C:/jruby/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/query_cache.rb:28:in
>`call'
>C:/jruby/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:361:in
>`call'
>C:/jruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/string_coercion.rb:25:in
>`call'
>C:/jruby/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/head.rb:9:in `call'
>C:/jruby/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/methodoverride.rb:24:in
>`call'
>C:/jruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/params_parser.rb:15:in
>`call'
>C:/jruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/session/cookie_store.rb:93:in
>`call'
>C:/jruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/failsafe.rb:26:in
>`call'
>C:/jruby/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/lock.rb:11:in `call'
>C:/jruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/dispatcher.rb:114:in
>`call'
>C:/jruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/reloader.rb:34:in
>`run'
>C:/jruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/dispatcher.rb:108:in
>`call'
>C:/jruby/lib/ruby/gems/1.8/gems/glassfish-1.0.2-universal-java/lib/rack/adapter/rails.rb:133:in
>`call'
>C:/jruby/lib/ruby/gems/1.8/gems/glassfish-1.0.2-universal-java/lib/rack/handler/grizzly.rb:55:in
>`call'
>
>I then tried setting up my routing like this:
>
>map.resources :receta
>
>  And it worked.  Can someone please clarify why with :recetas it didn't
>work?  What difference does it make to declare a resource with an "s" at
>the end.  Any info will be greatly appreciated.  Thanks in advance.
>
>
>Note: I removed the default routes for both attempts.
>-- 
>Posted via http://www.ruby-forum.com/.
>
>-- 
>You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
>To post to this group, send email to rubyonrails-talk@googlegroups.com.
>To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
>For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
>

tuti plain wrote:

C:/jruby/lib/ruby/gems/1.8/gems/glassfish-1.0.2-universal-java/lib/rack/adapter/rails.rb:133:in `call' C:/jruby/lib/ruby/gems/1.8/gems/glassfish-1.0.2-universal-java/lib/rack/handler/grizzly.rb:55:in `call'

I then tried setting up my routing like this:

map.resources :receta

  And it worked. Can someone please clarify why with :recetas it didn't work? What difference does it make to declare a resource with an "s" at the end. Any info will be greatly appreciated. Thanks in advance.

Note: I removed the default routes for both attempts.

Try this:

map.resources :recetas, :controller => "receta"