# Map.resources :controller and form\_for

**URL:** <https://www.ruby-forum.com/t/map-resources-controller-and-form-for/175169>\
**Category:** Rails\
**Created:** [September 9, 2009, 9:34am UTC](https://www.ruby-forum.com/t/map-resources-controller-and-form-for/175169 "2009-09-09T09:34:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Perceptes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e68b1a/32.png) [@Perceptes](https://www.ruby-forum.com/u/Perceptes)\
**Post date:** [September 9, 2009, 9:34am UTC](https://www.ruby-forum.com/t/map-resources-controller-and-form-for/175169/1 "2009-09-09T09:34:49Z")

</div>

I have a route like this:

map.resources :blog, :controller =\> ‘posts’

This seems to confuse form\_for’s model introspection when using this  
syntax:

form\_for @post do |f| … end

When I go to a page that has that code, I get a NoMethodError:

undefined method `posts\_path’ for #ActionView::Base:0x103dd2030

I’ve discovered I can fix it by doing:

form\_for @post, :url =\> { :action = ‘whatever-action-it-should-have-  
been’ } do |f| … end

Do I need to manually set the :url parameter like this every time I  
use form\_for or is there a way to get it to globally recognize my  
altered named routes?

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![Perceptes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e68b1a/32.png) [@Perceptes](https://www.ruby-forum.com/u/Perceptes)\
**Post date:** [September 9, 2009, 12:05pm UTC](https://www.ruby-forum.com/t/map-resources-controller-and-form-for/175169/2 "2009-09-09T12:05:53Z")

</div>

As far as I understand, you are trying to generate URLs with resource  
name “blog” when actual controller is named posts. So the correct path  
should be blogs\_path (for your example) and not posts\_path, and I  
think it’s a good idea that you specify it always. I don’t know if you  
can specify it globally.

But if it suits your need you can use :as. From rails guide:

> **[Rails Routing from the Outside In — Ruby on Rails Guides](https://guides.rubyonrails.org/routing.html)**
>
> Rails Routing from the Outside InThis guide covers the user-facing features of Rails routing.After reading this guide, you will know: How to interpret the code in config/routes.rb. How to construct your own routes, using either the preferred...

map.resources :photos, :as =\> “images”  
will recognize incoming URLs containing image but route the requests  
to the Photos controller

## Thanks, Abhinav

à¤…à¤­à¤¿à¤¨à¤µ  
[http://twitter.com/abhinav](http://twitter.com/abhinav)

---

<div class="post-metadata">

**Author:** ![Perceptes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e68b1a/32.png) [@Perceptes](https://www.ruby-forum.com/u/Perceptes)\
**Post date:** [September 9, 2009, 9:13pm UTC](https://www.ruby-forum.com/t/map-resources-controller-and-form-for/175169/3 "2009-09-09T21:13:53Z")

</div>

I actually used :as before using :controller, and while it recognized  
routes using the “aliased” name, the URL helpers generated links using  
the “real” name. Perhaps I was using the wrong helpers, though. I will  
look into it again. Thanks for your response!

---

<div class="post-metadata">

**Author:** ![Perceptes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e68b1a/32.png) [@Perceptes](https://www.ruby-forum.com/u/Perceptes)\
**Post date:** [September 9, 2009, 9:54pm UTC](https://www.ruby-forum.com/t/map-resources-controller-and-form-for/175169/4 "2009-09-09T21:54:51Z")

</div>

Trying it again, using :on did what I was expecting. I think I most  
have mistakenly tried used alias\_path instead of original\_path when I  
was trying it the first time. Case closed! Thanks again!
