# Controllers and form\_for

**URL:** <https://www.ruby-forum.com/t/controllers-and-form-for/166312>\
**Category:** Rails\
**Created:** [April 23, 2009, 7:29pm UTC](https://www.ruby-forum.com/t/controllers-and-form-for/166312 "2009-04-23T19:29:53Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 23, 2009, 7:29pm UTC](https://www.ruby-forum.com/t/controllers-and-form-for/166312/1 "2009-04-23T19:29:53Z")

</div>

I’m a bit confused on how this works. My form is sending to a weird  
location. Here’s my situation:

I have a model: youtube.rb  
I have a controller called: youtube\_editor\_controller.rb

In my youtube\_editor view, i have new.html.erb, where I’m trying to  
make a form for the var I created in my youtube\_editor\_controller.rb:

def new  
@video\_new = Youtube.new  
end

SO, I use the form\_for @video\_new, but when I view the page, the form  
action="/youtubes". Why is it doing that? Did I define “youtubes” or  
is it just pluralizing my model name? Where does it decide which  
controller to go to?

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 23, 2009, 7:33pm UTC](https://www.ruby-forum.com/t/controllers-and-form-for/166312/2 "2009-04-23T19:33:59Z")

</div>

On 23 Apr 2009, at 18:29, removed\_email\_address@domain.invalid wrote:

> SO, I use the form\_for @video\_new, but when I view the page, the form  
> action="/youtubes". Why is it doing that? Did I define “youtubes” or  
> is it just pluralizing my model name? Where does it decide which  
> controller to go to?

that comes from your routes.

Fred

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 23, 2009, 7:48pm UTC](https://www.ruby-forum.com/t/controllers-and-form-for/166312/3 "2009-04-23T19:48:37Z")

</div>

OK, I have this in my routes:

map.resources :youtube\_editor  
map.resources :youtubes

I deleted youtubes and I got an error. (I think “youtube” is my model  
name, but “youtubes” may be my table name. “youtube\_editor” is my  
controller. How do I get the resource youtube\_editor linked to the  
@video\_new variable? (if that’s how it works…)

THanks!

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 23, 2009, 8:50pm UTC](https://www.ruby-forum.com/t/controllers-and-form-for/166312/4 "2009-04-23T20:50:15Z")

</div>

So, models and controllers should always have the same name?

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 23, 2009, 9:30pm UTC](https://www.ruby-forum.com/t/controllers-and-form-for/166312/5 "2009-04-23T21:30:29Z")

</div>

brent wejrowski wrote:

> So, models and controllers should always have the same name?

Yes. Standard practice has the model called Thing, the controller  
called ThingsController, and the database table called things.

Note that you will not necessarily need all three of those for any given  
Thing. It is quite common to have models without associated controllers  
and vice versa.

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 23, 2009, 8:38pm UTC](https://www.ruby-forum.com/t/controllers-and-form-for/166312/6 "2009-04-23T20:38:31Z")

</div>

On 23 Apr 2009, at 18:47, removed\_email\_address@domain.invalid wrote:

> 

you’ll make life easier for yourself if you stick to the default (ie  
the controller for editing instances of Youtube should be  
youtubes\_controller). You should be able to the :controller option to  
override that if you want.

Fred
