[rspec-users] oddness with messages_path
apremdas at gmail.com
Mon Nov 28 09:45:21 EST 2011
On 27 November 2011 06:15, Cynthia Kiser <cnk at ugcs.caltech.edu> wrote:
> Quoting Justin Ko <jko170 at gmail.com>:
>> Run "rake routes" and you'll see what the two "paths" generate.
> Rake routes didn't really give me much insight - but playing around in
> the console did. Any argument to messages_path gets interpreted as a
> format - even an integer.
> > app.messages_path(:pdf)
> => "/messages.pdf"
> > app.messages_path("doc")
> => "/messages.doc"
> > app.messages_path(1)
> => "/messages.1"
> That hadn't occured to me - even once someone pointed out my
> singular/plural problem.
Because you were running a singular route the parameter you were
passing was matching the :format part of the route. So what you were
doing was telling the routing that instead of html you wanted your
message (which resolves to the id of the message). So instead of
xxx.html you are getting xxx.1 or whatever the id is.
Rake routes tells you this:
Singular resource - resource :users, :only => :show
users GET /users(.:format)
Plural resource - resources :users, :only => :show
user GET /users/:id(.:format) # you can pass an id to this route
You can see that with the singular resource passing an :id to the
users_path makes no sense, as the route can't understand it.
> Cynthia N. Kiser
> cnk at ugcs.caltech.edu
> rspec-users mailing list
> rspec-users at rubyforge.org
More information about the rspec-users