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:
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:

Receta#index

Find me in app/views/receta/index.html.erb

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:inconst_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:inconstantize’
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:inconstantize’
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:inrecognize’
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:indispatch’
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:inbuild_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:incall’
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:incache’
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:incall’
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:incall’
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:incall’
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:incall’
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:incall’
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:incall’
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:incall’

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"?[email protected]?写道:

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:incall’

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”

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs