Topic: Currency, and foreign keys
I'm still learning my way around Rails, & spent this evening creating my data models, & learning how to use migrations. As a result of this I have a couple of questions, one pertaining to currency, the other to foreign keys.
Hopefully someone here will have the time & patience to answer them :-)
Firstly, currency values - what type should I be using to store them? I was thinking of using decimal, but it turns out that I can't do that, because migration doesn't support decimal:
-- add_column(:roles, :billing_period_cost, :decimal)
You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occured while evaluating nil.
So, I'm using integer at the moment (storing the number of cents), but that's not ideal, as I'll have to translate the user input (in the form "123.45") to cents (12345) at every point.
Secondly, foreign keys. I have a Payment model, which contains a category_id column that identifies a Category. In the models, I have:
class Payment < ActiveRecord::Base
class Category < ActiveRecord::Base
However, the UI created by Rails doesn't show the Category in the Payment. If for example I navigate to /payment/new, I see all of my fields in the new Payment, except for category_id.
Am I missing something here? Do I need to manually code the category integration in the views for new, show, list, etc.? Or do I need to take some other step to notify Rails that there's a relationship between the two tables?
TIA for any advice.
Last edited by duncan_bayne (2006-12-11 05:45:45)