Forum: Ruby on Rails controllers/views in sub-folders and broken routes

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Greg D. (Guest)
on 2009-02-03 22:19
(Received via mailing list)
I'm having some issues with routing when using controllers in
sub-folders.

I have controllers in an admin folder that look like this:


class Admin::UsersController < ApplicationController
end


My link_to_remote calls look like this:

<%= link_to_remote 'Users', :url => { :controller => 'admin/users',
:action => :index } %>


And then when I deploy to production I get errors such as:

ActionView::MissingTemplate (Missing template admin/users.erb in view
path /rails/myapp/releases/20090203200508/app/views:):


In production it asks for the wrong template.  It should be asking for
the template app/views/admin/users/index.html.erb like it does in
development.


I found if I add a route:

map.connect 'admin/users', :controller => 'admin/users', :action     =>
'index'

my link_to_remote calls do begin to work in both development and
production.

I do not want to add a route for every single url I have in my admin.
What's the solution?


Using Rails 2.2.2.


Thanks,


--
Greg D.
http://destiney.com/
Greg D. (Guest)
on 2009-02-03 22:21
(Received via mailing list)
On Tue, Feb 3, 2009 at 2:18 PM, Greg D. <removed_email_address@domain.invalid> 
wrote:
> I do not want to add a route for every single url I have in my admin.

Also, forgot to mention..  I tried this:

map.connect 'admin/:controller/:action/:id'

But I didn't see any change.


Thanks,



--
Greg D.
http://destiney.com/
Daly (Guest)
on 2009-02-03 23:21
(Received via mailing list)
I don't think you can supply :controller => "some_controller" in
link_to_remote, only :action and :id are valid. I think you should
embrace the resourceful way of doing things and add this to your
routes.rb file:

map.resources :users, :controller => 'admin/users', :name_prefix =>
'admin_'

This would then give you many clean named routes, one of which is
admin_users_path which will link to what you want. Now you can put:

:url => admin_users_path

I have not tested this, but I'm pretty sure it will work.
Greg D. (Guest)
on 2009-02-03 23:27
(Received via mailing list)
On Tue, Feb 3, 2009 at 3:20 PM, Daly <removed_email_address@domain.invalid> 
wrote:
> I don't think you can supply :controller => "some_controller" in
> link_to_remote,

I have about half-a-dozen Rails apps that say otherwise  :)

> only :action and :id are valid. I think you should
> embrace the resourceful way of doing things and add this to your
> routes.rb file:

I do not want resources.  I just want routes that work without adding
an entry for each url in routes.rb.

> map.resources :users, :controller => 'admin/users', :name_prefix =>
> 'admin_'
>
> This would then give you many clean named routes, one of which is
> admin_users_path which will link to what you want. Now you can put:
>
> :url => admin_users_path
>
> I have not tested this, but I'm pretty sure it will work.

Yes, it will, but that's not what I want for this app.  I just want my
admin controllers in a folder, that's it.


Thanks all the same.



--
Greg D.
http://destiney.com/
Julian L. (Guest)
on 2009-02-04 02:00
(Received via mailing list)
Ah if only merb's routes were in rails already

Anyway, what OTHER routes do you have in front of the default route?
Coz when you're using namespaces controllers, it matters. Aside from
this, DHH has made it pretty clear this isn't a great thing to do.

Blog: http://random8.zenunit.com/
Learn rails: http://sensei.zenunit.com/
Greg D. (Guest)
on 2009-02-04 22:33
(Received via mailing list)
On Tue, Feb 3, 2009 at 5:59 PM, Julian L. <removed_email_address@domain.invalid>
wrote:
> Anyway, what OTHER routes do you have in front of the default route?
> Coz when you're using namespaces controllers, it matters. Aside from
> this, DHH has made it pretty clear this isn't a great thing to do.


Having a single admin controller with 807345029 lines of code in it
clearly isn't a great thing to do either.



--
Greg D.
http://destiney.com/
Julian L. (Guest)
on 2009-02-05 02:19
(Received via mailing list)
No, but putting admin_ in front of your admin controllers is fine.

Blog: http://random8.zenunit.com/
Learn rails: http://sensei.zenunit.com/
Greg D. (Guest)
on 2009-02-05 20:29
(Received via mailing list)
On Wed, Feb 4, 2009 at 6:18 PM, Julian L. <removed_email_address@domain.invalid>
wrote:
>
> No, but putting admin_ in front of your admin controllers is fine.

That's not very DRY.


--
Greg D.
http://destiney.com/
Julian L. (Guest)
on 2009-02-06 05:10
(Received via mailing list)
So use a loop with send to map  LOL. A class def is only ruby after all

Blog: http://random8.zenunit.com/
Learn rails: http://sensei.zenunit.com/
Julian L. (Guest)
on 2009-02-06 05:14
(Received via mailing list)
Here's what I do in my app

   %w[wip businesses people journal microsites brief reports
search].each do |controller_name|
     map.connect "admin/#{controller_name}/:action/:id", :controller
=> "admin_#{controller_name}"
   end

I'm sure you could probably do something like this, too, tho it's
untested:

   %w[wip businesses people journal microsites brief reports
search].each do |controller_name|
     map.connect "admin/#{controller_name}/:action/:id", :controller
=> "admin/#{controller_name}"
   end
This topic is locked and can not be replied to.