Plural and Unknown Controllers

Hello all,

I just found this forum whilst looking for some help on a problem I’ve
encountered and would be grateful for any assistance. I’ve just started
to learn Ruby hands-on, and am learning as I go so please forgive any
errors in terminology I may make.

I’m developing a website about the airbus fleet of aircraft. I plan to
have one table with info about the aircraft, called aircrafts, it will
remain static apart from one comments field which users can add to.

The next table is the users table, called users.

I created an aircraft table, model and controller, but then realised my
mistake in not pluralising the table name, so went back in did that,
restarted the server and now I have both an aircraft and aircrafts
controller and model file. The tutorials I’ve seen indicate that the
table name should be plural, but the controller and model names were
always singular.

So I’m not sure which controller/model file to use. The same thing
happened for user and users.

Also, whenever I go to:
http://localhost:3000/airbus/aircraft or any of the other controller
names, i get I get a 'No action responding to aircraft" error, replace
aircraft with the name of the controller.

I’ve created scaffolds for aircraft and user (singular).

So basically, do i only have to use plurals for the table names, and can
therefore delete any other plural controllers/models/anything else, or
do I need both?

Thanks, and I hope this makes some kind of sense.

Hussein.

Hello all,
[snip]
So basically, do i only have to use plurals for the table names, and can
therefore delete any other plural controllers/models/anything else, or
do I need both?

Thanks, and I hope this makes some kind of sense.

Rails will let you do anything, but the convention is this given “foo”

SQL Table: foos
Controller: app/controllers/foo_controller.rb (class FooController)
Model: app/controllers/foo_model.rb (class Foo)
Views: app/views/foo

Take a look at the output of the following commands:

./script/generate controller
./script/generate model

These will setup the necessary stub files for you to fill out (and set
the
right plurization for you)

So you could do say…

./script/generate controller foo
./script/generate model foo

and you’d end up with the filenames I mention above.

-philip

OK, so from what you’re saying, I would delete the pluralised files for
the model and controller.

I actually just deleted the entire application directory at the root
level. there wasn’t any development code there so it didn’t waste
anything.

I just re-created the app:
rails airbus
ruby script/server -p 3000
ruby script/generate model aircraft
ruby script/generate controller aircraft
ruby script/generate scaffold aircraft
ruby script/generate model user
ruby script/generate controller user
ruby script/generate scaffold user

I then modified database.yml file to point to the right database.
Restarted the webBRICK server, and now going back to the app/controllers
directory, I have the following files:

aircraft_controller.rb
aircrafts_controller.rb
application.rb
user_controller.rb
users_controller.rb

As you can see from the commands above, I never specified plurals - the
only plurals that exist are in my table names in the database. So I’m
now really confused about which files I use, and why it generated tw of
them, one with a singular name and one plural.

Another problem I’ve noticed is that I am getting a “Routing Error -
Recognition failed for airbus/aircraft” or whatever the controller name
is. I don’t understand this, as I thought Ruby/Rails worked right of
the box even without any user coding. The only thing I haven’t done yet
is to put in:

model :?
scaffold :?

Where ? represents the same name as that of the controller file, in each
controller file.

Sorry that this is rather jumbled, but maybe I’m getting conflicting
instructions from what I know and what I’m reading in the tutorials?

I apprciate the help.

Hussein.

Sorry, couldn’t work out how to edit my post, but I realised I was
typing the web address wrong. I thought the path to the controllers was
appname/controller, when it’s just controller. Man, this could get
confusing if there are multiple apps on the same system.

Anyway, both http://localhost:3000/aircraft and
http://localhost:3000/aircrafts work, showing the contents of the same
table. Original question stands, do I have to keep both the singular
and plural files, or can I remove one?

Sorry again.

Hussein.

Alright…a couple of points.

  1. The scaffold command creates model, view and controller files, and
    it likes plural for the controller and view names. That is why you have
    duplicates. You made your own controller with the singular name, and
    scaffold made the plural one. You can go back and delete the singular
    ones.

So the quickest way to a running app is:

a. rails airbus
b. configure the database.yaml file
c. ruby script/generate scaffold aircraft
d. ruby script/generate scaffold user
e. ruby script/server

  1. The WebBrick server is just meant for testing one application at a
    time. You will never have two apps at localhost:3000. But can have
    multiple instances of Webrick running on different ports. eg. one on
    localhost:3000 and one at localhost:3001.

Hi, Thanks very much for your post. I understand now and will use just
the scaffold to create my frameworks. thanks also for the explanation
about running multiple apps.

Hussein.