# Resources, Modules, and Nesting (URL Helper errors)

**URL:** <https://www.ruby-forum.com/t/resources-modules-and-nesting-url-helper-errors/89835>\
**Category:** Rails\
**Created:** [March 23, 2007, 1:12am UTC](https://www.ruby-forum.com/t/resources-modules-and-nesting-url-helper-errors/89835 "2007-03-23T01:12:35Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![stephanie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3ab097/32.png) [@stephanie](https://www.ruby-forum.com/u/stephanie)\
**Post date:** [March 23, 2007, 1:12am UTC](https://www.ruby-forum.com/t/resources-modules-and-nesting-url-helper-errors/89835/1 "2007-03-23T01:12:35Z")

</div>

Hi,

I am trying to create REST routes non-standard setup. The rest url  
helpers give an error when I try to use a module controller for a  
nested resource.

Works  
map.resources :bar, :controller =\> ‘module/bar’

Works  
map.resources :foos do |foo|  
foo.resources :bar  
end

Doesn’t work (url helpers broken)  
map.resources :foos do |foo|  
foo.resources :bar, :controller =\> ‘module/bar’  
end

The URL helper error is…  
ActionView::TemplateError (bar\_url failed to generate from  
{:action=\>“index”, :controller=\>“module/bar”, :foo\_id=\>“1”}, expected:  
{:action=\>“index”, :controller=\>“module/bar”}, diff: {:foo\_id=\>“1”})

Anybody have any suggestions on what is wrong? Is it just a limitation  
or feature of rest routes?

Thanks,  
Stephanie

---

<div class="post-metadata">

**Author:** ![stephanie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3ab097/32.png) [@stephanie](https://www.ruby-forum.com/u/stephanie)\
**Post date:** [March 23, 2007, 1:52am UTC](https://www.ruby-forum.com/t/resources-modules-and-nesting-url-helper-errors/89835/2 "2007-03-23T01:52:38Z")

</div>

Hey,

could be a pluralization issue:

map.resources :foos do |foo|  
map.resources :bars, :controller =\> ‘module/bar’  
end

note I said :bars not :bar

HTH,  
Trevor

---

<div class="post-metadata">

**Author:** ![stephanie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3ab097/32.png) [@stephanie](https://www.ruby-forum.com/u/stephanie)\
**Post date:** [March 23, 2007, 2:08am UTC](https://www.ruby-forum.com/t/resources-modules-and-nesting-url-helper-errors/89835/3 "2007-03-23T02:08:39Z")

</div>

Hi Trever,

Thanks for the reply. Sorry for the typo. My email should say bars (a  
typo in translation to a question).

map.resources :bars, :controller =\> 'module/bars

My code actually did have the right pluralization. I copied the code  
out of the nesting and tested it unnested. All of the helpers worked  
with a module resource it isn’t nested.

-Stephanie

’

---

<div class="post-metadata">

**Author:** ![stephanie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3ab097/32.png) [@stephanie](https://www.ruby-forum.com/u/stephanie)\
**Post date:** [March 23, 2007, 2:45am UTC](https://www.ruby-forum.com/t/resources-modules-and-nesting-url-helper-errors/89835/4 "2007-03-23T02:45:41Z")

</div>

Hey Stephanie,

interesting…

to be honest I’m not even trying it out with a controller inside a  
module because the error you’re getting seems to be coming from the  
url\_helpers, which don’t care about controllers as such.

So, at the risk of sending you on a wild goose chase, I’ll make a guess:

I’m betting you’ve got “map.resources :bars” in more than one place  
in your routes.rb - am I right?

Trevor

---

<div class="post-metadata">

**Author:** ![stephanie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3ab097/32.png) [@stephanie](https://www.ruby-forum.com/u/stephanie)\
**Post date:** [March 23, 2007, 3:53am UTC](https://www.ruby-forum.com/t/resources-modules-and-nesting-url-helper-errors/89835/5 "2007-03-23T03:53:45Z")

</div>

Thanks for trying to track this down. I have no other references  
to :bars in the routes. I also do not have /:controller/:action/:id as  
a route.

However, in my controllers folder I do have a

app/controllers/bars\_controller.rb  
app/controllers/foo/bars\_controller.rb (this is subclassed from  
controllers/bars\_controller.rb)

Could this be causing the problem?

-Stephanie

---

<div class="post-metadata">

**Author:** ![stephanie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3ab097/32.png) [@stephanie](https://www.ruby-forum.com/u/stephanie)\
**Post date:** [March 23, 2007, 6:36am UTC](https://www.ruby-forum.com/t/resources-modules-and-nesting-url-helper-errors/89835/6 "2007-03-23T06:36:54Z")

</div>

Stephanie,

I’m confident that the names of your controllers isn’t the source of  
the problem - I can use utterly bogus controller names (and modules)  
in map.resources calls and it has no effect on url helpers.

Is this something as simple as that you’re not actually passing all  
the required information to the url helpers for your nested  
resource? As in:

bar\_url(‘a\_foo’, ‘a\_bar’) #=\> http//host.com/foos/a\_foo/bars/a\_bar

Trevor

---

<div class="post-metadata">

**Author:** ![stephanie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3ab097/32.png) [@stephanie](https://www.ruby-forum.com/u/stephanie)\
**Post date:** [March 23, 2007, 4:05am UTC](https://www.ruby-forum.com/t/resources-modules-and-nesting-url-helper-errors/89835/7 "2007-03-23T04:05:45Z")

</div>

I tried changing the super controller to another name. That way the  
only bars controller would be foo/bars\_controller.rb. This still gave  
me the same URL helper problems as described above.

I am back to suspecting is modules + nested resources is the  
problem???

-Stephanie

---

<div class="post-metadata">

**Author:** ![stephanie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3ab097/32.png) [@stephanie](https://www.ruby-forum.com/u/stephanie)\
**Post date:** [March 30, 2007, 1:34pm UTC](https://www.ruby-forum.com/t/resources-modules-and-nesting-url-helper-errors/89835/8 "2007-03-30T13:34:20Z")

</div>

Hi Stephanie,

Have found a solution to your problem? I have the same problem as well.  
My routing looks as follows;

map.resources :pictures, :controller =\> ‘user\_pictures’, :path\_prefix =\>  
‘/:user\_uid’, :name\_prefix =\> ‘user\_’, :requirements =\> { :user\_uid =\>  
/shafeer/ } do |picture|  
picture.resources :exhibitions, :controller =\>  
‘picture\_exhibitions’, :name\_prefix =\> ‘user\_picture\_’  
end

and then;

map.resource :myapp, :controller =\> ‘myapp/index’ do |myapp|  
myapp.resources :pictures, :controller =\> ‘myapp/pictures’,  
:name\_prefix =\> ‘myapp\_’ do |picture|  
picture.resources :exhibitions, :controller =\>  
‘myapp/picture\_exhibitions’, :name\_prefix =\> ‘myapp\_picture\_’  
end  
end

The helper method myapp\_pictures\_path produces the right path #=\>  
[http://host.com/myapp/pictures](http://host.com/myapp/pictures).

But the problem I have is with the controller, the routing chooses the  
wrong controller, that is, /app/controllers/user\_pictures\_controller.rb  
instead of  
/app/controllers/myapp/pictures\_controller.rb

Any idea why is that?

Thanks and Regards,  
Shafeer.
