# Form\_for syntax?

**URL:** <https://www.ruby-forum.com/t/form-for-syntax/172383>\
**Category:** Rails\
**Created:** [July 20, 2009, 9:01pm UTC](https://www.ruby-forum.com/t/form-for-syntax/172383 "2009-07-20T21:01:36Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![elliottg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/b77776/32.png) [@elliottg](https://www.ruby-forum.com/u/elliottg)\
**Post date:** [July 20, 2009, 9:01pm UTC](https://www.ruby-forum.com/t/form-for-syntax/172383/1 "2009-07-20T21:01:36Z")

</div>

I have been using this namespaced form\_for syntax with no problems:  
\<% form\_for [:admin, @products] do |f| %\>

However, now that I am working with a model and controller called  
“news” which has no differentiation between singular and plural…

\<% form\_for [:admin, @news] do |f| %\>

… I am getting this exception when running my tests:

ActionView::TemplateError: admin\_news\_url failed to generate from  
{:controller=\>“adminl/news”, :action=\>“show”} - you may have ambiguous  
routes, or you may need to supply additional parameters for this  
route. content\_url has the following required parameters: [“admin”,  
“news”, :id] - are they all satisfied?

Rake Routes is showing me that I can get news#index via  
sitecontrol\_news\_index.

I just can’t figure out the syntax to make it all work within the  
admin namespacing context.

Thanks for the help.  
Elliott

---

<div class="post-metadata">

**Author:** ![elliottg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/b77776/32.png) [@elliottg](https://www.ruby-forum.com/u/elliottg)\
**Post date:** [July 20, 2009, 9:34pm UTC](https://www.ruby-forum.com/t/form-for-syntax/172383/2 "2009-07-20T21:34:57Z")

</div>

You might consider adding an inflection for news in your config/  
initializers/inflections.rb. That will tell Rails that the plural of  
news is news. There are examples in the Rails-generated file.

---

<div class="post-metadata">

**Author:** ![elliottg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/b77776/32.png) [@elliottg](https://www.ruby-forum.com/u/elliottg)\
**Post date:** [July 20, 2009, 9:38pm UTC](https://www.ruby-forum.com/t/form-for-syntax/172383/3 "2009-07-20T21:38:27Z")

</div>

Hi –

On Mon, 20 Jul 2009, elliottg wrote:

> ActionView::TemplateError: admin\_news\_url failed to generate from  
> {:controller=\>“adminl/news”, :action=\>“show”} - you may have ambiguous

Is that “adminl” a typo in your code, or just in the email?

> routes, or you may need to supply additional parameters for this  
> route. content\_url has the following required parameters: [“admin”,  
> “news”, :id] - are they all satisfied?
> 
> Rake Routes is showing me that I can get news#index via  
> sitecontrol\_news\_index.
> 
> I just can’t figure out the syntax to make it all work within the  
> admin namespacing context.

I’m not sure exactly how you’ve got it set up, but starting at the  
simplest case: if you have this in your routes.rb:

map.namespace :admin do |a|  
a.resources :news  
end

and if @news is a News object, and you’ve got an admin/news  
controller, you should be OK.

David

–  
David A. Black / Ruby Power and Light, LLC  
Ruby/Rails consulting & training: [http://www.rubypal.com](http://www.rubypal.com)  
Now available: The Well-Grounded Rubyist ([The Well-Grounded Rubyist](http://manning.com/black2))  
Training! Intro to Ruby, with Black & Kastner, September 14-17  
(More info: [http://rubyurl.com/vmzN](http://rubyurl.com/vmzN))

---

<div class="post-metadata">

**Author:** ![elliottg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/b77776/32.png) [@elliottg](https://www.ruby-forum.com/u/elliottg)\
**Post date:** [July 20, 2009, 10:19pm UTC](https://www.ruby-forum.com/t/form-for-syntax/172383/4 "2009-07-20T22:19:57Z")

</div>

Thanks for the input guys.

The “adminl” is a email typo only…

Here’s a truncated version of my route config.

map.namespace :admin do | admin |  
admin.resources :news, :collection =\> {:sort =\> :post}  
end

My tests confirm that news\_controller.rb#new is indeed sending out a  
new @news object. And the directory/namespacing is correct for sure. I  
have already built out several other namespaced resource stacks for  
this app. Is there a more verbose syntax I can try in form\_for that  
may allow me to get closer to the metal on this one?

Thanks!

---

<div class="post-metadata">

**Author:** ![elliottg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/b77776/32.png) [@elliottg](https://www.ruby-forum.com/u/elliottg)\
**Post date:** [July 20, 2009, 9:38pm UTC](https://www.ruby-forum.com/t/form-for-syntax/172383/5 "2009-07-20T21:38:28Z")

</div>

Hi –

On Mon, 20 Jul 2009, s.ross wrote:

> You might consider adding an inflection for news in your config/  
> initializers/inflections.rb. That will tell Rails that the plural of  
> news is news. There are examples in the Rails-generated file.

It’s already there. I don’t think this is actually a singular/plural  
issue.

David

–  
David A. Black / Ruby Power and Light, LLC  
Ruby/Rails consulting & training: [http://www.rubypal.com](http://www.rubypal.com)  
Now available: The Well-Grounded Rubyist ([The Well-Grounded Rubyist](http://manning.com/black2))  
Training! Intro to Ruby, with Black & Kastner, September 14-17  
(More info: [http://rubyurl.com/vmzN](http://rubyurl.com/vmzN))

---

<div class="post-metadata">

**Author:** ![elliottg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/b77776/32.png) [@elliottg](https://www.ruby-forum.com/u/elliottg)\
**Post date:** [July 20, 2009, 10:45pm UTC](https://www.ruby-forum.com/t/form-for-syntax/172383/6 "2009-07-20T22:45:06Z")

</div>

I figured it out. It was directly related to the form\_for syntax. I  
guess that when rails generates the alternative explicit index route.  
In this case “admin\_news\_index” vs “admin\_news” a more explicit syntax  
is needed.

Instead of this:

\<% form\_for [:admin, @news] do |f| %\>

I found this solved my problem:

\<% form\_for @news, :url =\> admin\_news\_index\_path do |f| %\>
