Surprising route behavior

5 views
Skip to first unread message

David Mathers

unread,
Aug 24, 2009, 10:39:46 AM8/24/09
to hobo...@googlegroups.com
Hello,

Based on the fact that hobo_model_controller takes a model name as an
argument, I assumed that if I created a Foo resource and then replaced
my FoosController with:

class BarsController < ApplicationController
hobo_model_controller Foo
auto_actions :all
end

That I would then have bar routes instead of foo routes. But it turns
out the routes are named after models. It seems very strange to me to
not name routes after controllers. Is there a reason for this?

I went ahead and redefined ModelRouter#plural to
"controller.controller_name" and ModelRouter#singular to
"controller.controller_name.singularize". Everything seems OK so far,
but I wanted to check and make sure it won't cause problems.

-david

Brett Nelson

unread,
Aug 24, 2009, 10:52:55 AM8/24/09
to Hobo Users
This is something I would very much like to do. Where did you define
these?

Brett

David Mathers

unread,
Aug 24, 2009, 3:07:02 PM8/24/09
to hobo...@googlegroups.com
The file is hobo/lib/hobo/model_router.rb

My old:

127 def plural
128 model.name.underscore.pluralize
129 end
130
131
132 def singular
133 model.name.underscore
134 end

My new:

127 def plural
128 # route by controller name not model name -dwm
129 #model.name.underscore.pluralize
130 controller.controller_name
131 end
132
133
134 def singular
135 # route by controller name not model name -dwm
136 #model.name.underscore
137 controller.controller_name.singularize
138 end

-david

Tom Locke

unread,
Aug 24, 2009, 3:31:33 PM8/24/09
to hobo...@googlegroups.com
> That I would then have bar routes instead of foo routes. But it turns
> out the routes are named after models. It seems very strange to me to
> not name routes after controllers. Is there a reason for this?

I think this was a mistake, as you point out.

> I went ahead and redefined ModelRouter#plural to
> "controller.controller_name" and ModelRouter#singular to
> "controller.controller_name.singularize". Everything seems OK so far,
> but I wanted to check and make sure it won't cause problems.

Maybe we should make this change before 1.0

Comments?

Tom

David Mathers

unread,
Aug 24, 2009, 4:14:16 PM8/24/09
to hobo...@googlegroups.com
On Mon, Aug 24, 2009 at 12:31 PM, Tom Locke<t...@tomlocke.com> wrote:
>
> Maybe we should make this change before 1.0
>
> Comments?

I say aye.

-david

David Mathers

unread,
Aug 24, 2009, 6:23:23 PM8/24/09
to hobo...@googlegroups.com
On Mon, Aug 24, 2009 at 12:31 PM, Tom Locke<t...@tomlocke.com> wrote:
>
> Comments?

I don't completely understand HoboHelper#object_url, but I think it
also needs to be updated to get link href from controller or will be
broken.

-david

Tom Locke

unread,
Aug 25, 2009, 5:57:26 AM8/25/09
to hobo...@googlegroups.com
> I don't completely understand HoboHelper#object_url, but I think it
> also needs to be updated to get link href from controller or will be
> broken.

Oh yes of course. I was forgetting all about this side of things when
I said we should make this change. Hobo really does work on the
assumption that the routes for an object are based on its class name.
Fixing this for routing is quite easy, but is breaks object_url which
is used all over the place in the view layer.

That'll teach me to dash off a reply without thinking it through : )

Tom

Owen

unread,
Aug 25, 2009, 10:52:21 AM8/25/09
to Hobo Users
Yes, I agree as well.

Owen

unread,
Aug 25, 2009, 10:53:46 AM8/25/09
to Hobo Users
I hear you. Actually, being model-centric is better IMHO.

Brett Nelson

unread,
Aug 25, 2009, 11:45:11 AM8/25/09
to Hobo Users
This issued could be solved by creating a hobo_model that isn't
connected to any database.

Brett

Tom Locke

unread,
Aug 25, 2009, 12:00:07 PM8/25/09
to hobo...@googlegroups.com
> I hear you. Actually, being model-centric is better IMHO.

The correct solution would probably be to make routing and URL
generation aware of view-hints.

Tom

Brett Nelson

unread,
Aug 25, 2009, 1:01:21 PM8/25/09
to Hobo Users
So say if one wanted to route http://myapp.com/calculator to a page
which performed calculator like functions, maybe metric/english
conversions, which had no need to be connected to a table named
"calculator" because there was no need to persist anything, would I
use view-hints to do this?

I can see the usefulness of Restful/Crud but I would like to build a
hybrid restful-crud / json+ajax application that does not need to be
indexable by search engines.

Brett

Matt Jones

unread,
Aug 25, 2009, 1:36:58 PM8/25/09
to hobo...@googlegroups.com
Note that there's nothing stopping you from just setting routes, or
even resource routes, in config/routes.rb just like a plain Rails app.

--Matt Jones

kevinpfromnm

unread,
Aug 25, 2009, 1:55:31 PM8/25/09
to Hobo Users
Hobo controllers are definitely model centric but you can still define
a regular controller and use dryml. Probably the way to do it, unless
there comes into being a tableless hobo model and even then, depends
on what you're doing as to whether you need a model or not.

On Aug 25, 11:01 am, Brett Nelson <blizzardvi...@gmail.com> wrote:
> So say if one wanted to route  http://myapp.com/calculatorto a page

Brett Nelson

unread,
Aug 25, 2009, 3:35:31 PM8/25/09
to Hobo Users
That seems reasonable and is probably the best way to do it. My
handicap is having started with hobo first and then having to learn
rails later...
Brett


On Aug 25, 10:55 am, kevinpfromnm <kevinpfro...@gmail.com> wrote:
> Hobo controllers are definitely model centric but you can still define
> a regular controller and use dryml.  Probably the way to do it, unless
> there comes into being a tableless hobo model and even then, depends
> on what you're doing as to whether you need a model or not.
>
> On Aug 25, 11:01 am, Brett Nelson <blizzardvi...@gmail.com> wrote:
>
> > So say if one wanted to route  http://myapp.com/calculatortoa page
Reply all
Reply to author
Forward
0 new messages