resources_controller does not like map.with_options

5 views
Skip to first unread message

walt

unread,
Apr 22, 2010, 6:40:56 AM4/22/10
to resources_controller
I have a peculiarity with resources_controller which I have not been
able to solve - and I hope that someone here has a better
understanding of Routing and ResourcesController <:)

In a project of mine, my routes.rb has


map.with_options :controller => 'homes' do |m|
m.hjt 'hjerteforeningen', :action => 'show', :id => 1
end


When I do (in console - but it acts the same in a browser)

> app.get "/hjerteforeningen"

My log says:

Processing HomesController#show (for 127.0.0.1 at 2010-04-22 12:37:17)
[GET]
Parameters: {"id"=>1}

Ardes::ResourcesController::ResourceMismatch (resources_controller
can't match the route to the resource specification
path: /hjerteforeningen
specification: enclosing: [*], resource :homes

I'm obviously doing something very wrong - I just can't point my
finger at it!

Somebody, please point your finger ;)

Cheers,
Walther

--
You received this message because you are subscribed to the Google Groups "resources_controller" group.
To post to this group, send email to resources_...@googlegroups.com.
To unsubscribe from this group, send email to resources_contro...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/resources_controller?hl=en.

Ian White

unread,
Apr 22, 2010, 6:46:48 AM4/22/10
to resources_...@googlegroups.com
Hi Walther,

rc uses the request path to do fancy enclosing resource loading and stuff.

So, when you have a non-standard (non restful) route, you need to give rc a hint to what the restful path is. to do this set the :resource_path param in the route

m.hjt 'hjerteforeningen', :action => 'show', :id => 1, :resource_path => '/homes/1'

Hope that helps,

CHeers,
Ian

walt

unread,
Apr 22, 2010, 7:01:10 AM4/22/10
to resources_controller
Hi Ian,

I'm overwhelmed by the attention on your part!

Sure - it did help - it helped a lot! :D

But now I'm faced with the offspring - how do I proceed with nested
resources?

In my routes.rb I have the default mapping like this:

map.resources :homes do |home|
home.resources :pages do |page|
page.resources :rendering_elements
end
home.resources :rendering_elements
end

- and with your help - I added:


map.with_options :controller => 'homes' do |m|
m.hjt 'hjerteforeningen', :action => 'show', :id =>
1, :resource_path => '/homes/1' do |m|
m.resources :pages, :resource_path => '/homes/1/pages' do |page|
page.resources :rendering_elements
end
m.resources :rendering_elements
end

But '/hjerteforeningen/pages/10' do not provide me with the content of
that resource - hmmm!?

I seem to keep getting myself into troubles :(

Ian White

unread,
Apr 22, 2010, 7:10:17 AM4/22/10
to resources_...@googlegroups.com
Hi walt,

I think you're getting into uncharted territory with trying to nest resources under a simple mapped route.

It looks like you want a singleton resource at the top instead. Check out the account pattern stuff mentioned in resources controller docs.

Cheers,
Ian

Sent from my iPhone
Reply all
Reply to author
Forward
0 new messages