I followed a tutorial step by step which resulted in what has been, for
me, the holy grail: a one-to-many relationship. A screenshot of what I
ended up with:
Name: Chili Cookoff
Budget: 150.0
Edit | Back
Itemized Expenses
2007-12-09 Fire Department $25.00
2007-12-10 Parties R Us $75.00
<http://expenses.googlecode.com/files/chili_cookoff.png>, clearly
demonstrating the "many" expenses per accounts; a "one-to-many"
relationship with CRUD interface.
The step which was most mysterious in the tutorial:
"Generate the scaffolding by typing
$ script/generate scaffold account expenses
That command generates a number of files for us; files we'd rather not
create by hand. The first parameter (account) specifies the name of the
model, which is generated in the app/models/account.rb file. The second
parameter (expenses) specifies the name of the controller, which is
generated in the app/controllers/expenses_controller.rb file. The
scaffold generator also created template files for the views of our
application."
<http://developer.apple.com/tools/rubyonrails.html>
This is all well and good, but the choice for the singular versus plural
choice is unclear to me. Both models are singular, as expected. Why,
then, is it "expenses" and not "expense" in the above scaffold command?
Is this significant, a typo, or is the name of the scaffold here
immaterial?
It strikes me that there's an intuitive mismatch between navigating to
<http://localhost:3000/expenses> and being presented with a listing of
accounts:
Listing accounts
Name Budget
Chili Cookoff 150.0 Show Edit Destroy
Car Wash 25.0 Show Edit Destroy
Pancake Breakfast 125.0 Show Edit Destroy
Dunk the Programmer 50.0 Show Edit Destroy
New account
rather than a listing of expenses.
Which brings me to my next question: what's the connection between the
model name, Expense, and the name of this particular controller,
expenses_controller.rb? Could it have been "script/generate scaffold
account foo", or was it critical that "expenses" match up with the
Expense model?
Also, I would like to apply this approach to <http://code.google.com/p/
strawr/source>, which I've started over with. The Category model has a
foreign key for the Feed model; it's a "one-to-many", one category having
many feeds, relationship. Once app/model/ is populated with the scaffold
command it will be that:
thufir@arrakis ~/Desktop/strawr/app/models $
thufir@arrakis ~/Desktop/strawr/app/models $ cat category.rb
class Category < ActiveRecord::Base
has_many :feed
end
thufir@arrakis ~/Desktop/strawr/app/models $
thufir@arrakis ~/Desktop/strawr/app/models $ cat feed.rb
class Feed < ActiveRecord::Base
belongs_to :category
end
thufir@arrakis ~/Desktop/strawr/app/models $
However, I haven't yet committed this change to the code repository.
When i visualize the CRUD layout I imagine a "Listing category" so that
clicking on "show" will display that particular category and its
potentially many feeds. That is, the many feeds which match that
particular category. It seem to me that the the URL "name" for the
"Listing category" should be "categories", meaning a controller named
"categories_controller.rb". However, to apply the pattern of the
tutorial I found on this topic, a one-to-many relationship, the command
would be:
script/generate scaffold category feeds
This will certainly result in "Listing categories", as that's the model
used, but the URL will be at /feeds/ which initially seems nonsensical.
Or, does it make more sense once "show" is clicked, and then there's a
feeds list and the URL "name" will suddenly make sense?
I don't want to make it complex, I'm just trying for something simple to
get started, but the naming conventions aren't making sense to me. I'm
not seeing how to apply this tutorial to my project, despite the
similarities :(
thanks,
Thufir
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org
Received on Mon Dec 10 13:52:58 2007