First up. Controllers are called the same as models! Example:
$ script/generate controller monkey
Started merb_init.rb ...
Loading Application...
Compiling routes..
Loaded DEVELOPMENT Environment...
exists app/controllers
create app/controllers/monkey.rb
and
$ script/generate model monkey
Started merb_init.rb ...
Loading Application...
Compiling routes..
Loaded DEVELOPMENT Environment...
exists app/models
create app/models/monkey.rb
So if you create a controller for monkeys and a model for monkeys, the two class names will both be called Monkey, except one will inherit from controller and the other from model.
In fairness to MERB the generators do warn you about this.
"The name 'Monkey' is reserved."But it doesn't explain why it is reserved and maybe I'm just thick but it stumped me for longer than it should have.
You never have a chance to make that mistake in Rails because controllers are always like "MonkeyController". (I don't know why merb didn't follow suit... DRYer? simpler?)
What I did to get around that was to make the controller plural. monkeys.rb
1 comments:
The convention in Merb is singular for models, plural for controllers.
So, you're work around is exactly right :)
The one downside to doing this is if you need a controller for a singular resource — say User — it will collide with the model.
There is no accepted convention for doing this ATM. Appending 'Controller' is probably the best way to go about it, but this means also adjusting routes to account for it — they assume the controller class doesn't have a suffix of any kind.
Post a Comment