# Form\_for resources with :singular specified

**URL:** <https://www.ruby-forum.com/t/form-for-resources-with-singular-specified/171418>\
**Category:** Rails\
**Created:** [July 2, 2009, 3:33am UTC](https://www.ruby-forum.com/t/form-for-resources-with-singular-specified/171418 "2009-07-02T03:33:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bryan-ash](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/59ef9b/32.png) [@bryan-ash](https://www.ruby-forum.com/u/bryan-ash)\
**Post date:** [July 2, 2009, 3:33am UTC](https://www.ruby-forum.com/t/form-for-resources-with-singular-specified/171418/1 "2009-07-02T03:33:00Z")

</div>

I fully suspect that I’m missing the point here somewhere so I promise  
I won’t be offended if you tell me I’m being daft.

My application rents equipment … not equipments. So I have the  
following:

map.resources :equipment, :singular =\> :equipment\_instance

class Equipment \< ActiveRecord::Base

class EquipmentController \< ApplicationController

The problem comes in my \_form.haml partial that is used by new.haml  
and edit.haml:

- form\_for @equipment do |f|

This gives me an error saying “Only get and post requests are allowed.  
(ActionController::MethodNotAllowed)”

I tried:

- form\_for @equipment, equipment\_instance\_path(@equipment) do |f|

That gives the same error.

There has to be something better than:

- form\_for @equipment, :url =\> (@equipment.new\_record? ?  
equipment\_path : equipment\_instance\_path(@equipment)), :html =\>  
(@equipment.new\_record? ? { :method =\> :post } : { :method =\> :put })  
do |f|

Why does Rails not introspect correctly in this case?

Bryan

---

<div class="post-metadata">

**Author:** ![bryan-ash](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/59ef9b/32.png) [@bryan-ash](https://www.ruby-forum.com/u/bryan-ash)\
**Post date:** [July 2, 2009, 9:41am UTC](https://www.ruby-forum.com/t/form-for-resources-with-singular-specified/171418/2 "2009-07-02T09:41:31Z")

</div>

2009/7/1 Bryan A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> - form\_for @equipment, :url =\> (@equipment.new\_record? ?  
> equipment\_path : equipment\_instance\_path(@equipment)), :html =\>  
> (@equipment.new\_record? ? { :method =\> :post } : { :method =\> :put })  
> do |f|
> 
> Why does Rails not introspect correctly in this case?

Is it possible that you could avoid the problem by a better choice of  
model/table name? The convention is to use a name that makes the code  
read well in your language, in this case I presume English. So for  
example you may have a table called items, which contains obviously a  
number of items and if you find one of them it is an item. Similarly  
another class can define has\_many :items, belongs\_to :item and so on  
and it reads well. Equipment is not a word that fits this pattern.  
One cannot have an equipment or many equipment, it just does not work.  
An item in the table is not an equipment. As you use the term  
equipment\_instance you could use that as the table name or there may  
be a better word. Think about how you or the specifier or end user  
would refer to a number of these objects to give you ideas.

Colin
