Custom route in Hobo

8 views
Skip to first unread message

Ronbo

unread,
Jun 18, 2010, 6:32:35 AM6/18/10
to Hobo Users
Hi all,

I've been struggling with routing for a custom action. I've read some
background on rails routing, and the hobo controller/routes doc, but
still scratching my head.

I have a method defined in the controller

... in controller
class UnitsController < ApplicationController
def duplicate
...
end
end


... in router
map.duplicate 'duplicate/:id', :controller => 'unit', :action =>
'duplicate'
- this results in urls formed as http://localhost:3000/duplicate/3
(not routed to controller). If I manually enter the correct URL in the
browser (http://localhost:3000/units/duplicate/3) it works.

If I change it to
map.duplicate 'units/duplicate/:id', :controller => 'unit', :action =>
'duplicate'
links are constructed like http://localhost:3000/units/duplicate/3,
but clicking on them results in:
NameError in UnitController#duplicate

uninitialized constant UnitController ...


in view (application.dryml)
i've tried:

<def tag="card" for="Unit">
<card class="unit" param="default" merge>
<header: param>
<editor:name if="&!this.verified"/> <%= link_to "Duplicate",
duplicate_path(this.id) %>
<collection:unit-versions><empty-message:></empty-
message:></collection>
</header:>
</card>
</def>

which results in the links described above.

and also the dryml way:

<def tag="card" for="Unit">
<card class="unit" param="default" merge>
<header: param>
<editor:name if="&!this.verified"/> <a
action="duplicate>Duplicate</a>
<collection:unit-versions><empty-message:></empty-
message:></collection>
</header:>
</card>
</def>

which only results in static text on the page, telling me hobo was
unable to construct a valid route.

I think I am missing something basic here. Any tips?

Thanks

Joachim

unread,
Jun 18, 2010, 6:36:20 AM6/18/10
to hobo...@googlegroups.com
W dniu 18.06.2010 12:32, Ronbo pisze:

> Hi all,
>
> I've been struggling with routing for a custom action. I've read some
> background on rails routing, and the hobo controller/routes doc, but
> still scratching my head.
>
> I have a method defined in the controller
>
> ... in controller
> class UnitsController < ApplicationController
> def duplicate
> ...
> end
> end
>
>
> ... in router
> map.duplicate 'duplicate/:id', :controller => 'unit', :action =>

Looks like you're using standard-looking route, it may be to let Hobo
handle routes

class UnitsController < ApplicationController
show_action :duplicate

Ronbo

unread,
Jun 18, 2010, 7:37:36 AM6/18/10
to Hobo Users
Just tried that - I still get error.

Bryan Larsen

unread,
Jun 18, 2010, 7:53:10 AM6/18/10
to hobo...@googlegroups.com
1) if you have show_action in your controller, you should remove it from
the router

2) test using another name. "duplicate" may be conflicting with
something somewhere. At the moment I don't have access to check.

Bryan

Joachim

unread,
Jun 18, 2010, 7:56:07 AM6/18/10
to hobo...@googlegroups.com
I think there is typo

W dniu 18.06.2010 12:32, Ronbo pisze:

> class UnitsController < ApplicationController


> NameError in UnitController#duplicate
>
> uninitialized constant UnitController ...

Unit_s_Controller in one place and Unit_without_s_Controller in the other.

Joachim

Ronbo

unread,
Jun 18, 2010, 8:22:14 AM6/18/10
to Hobo Users
Thanks Bryan - that was it. 'duplicate' was conflicting somewhere.
Changed and it is working as expected now.
Reply all
Reply to author
Forward
0 new messages