Forum: Ruby on Rails Controllers and form_for

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
(Guest)
on 2009-04-23 21:29
(Received via mailing list)
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?
Frederick C. (Guest)
on 2009-04-23 21:33
(Received via mailing list)
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
(Guest)
on 2009-04-23 21:48
(Received via mailing list)
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!
Frederick C. (Guest)
on 2009-04-23 22:38
(Received via mailing list)
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
brent wejrowski (Guest)
on 2009-04-23 22:50
(Received via mailing list)
So, models and controllers should always have the same name?
Marnen L. (Guest)
on 2009-04-23 23:30
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
removed_email_address@domain.invalid
This topic is locked and can not be replied to.