I'm not quite clear on the differences between
@payment = Payment.new
This creates an empty Payment object
@payment = Payment.new(params[:id])
This should give you an error..
@payment.attributes = params[:payment]
This takes an existing payment object (maybe initialized as your first
line) and sets all its attributes to the corresponding values in the
hash
@payment = Payment.new(params[:payment])
This creates a new payment object with its attributes initialized to
the corresponding values in the hash
The easiest is just to do
@payment = Payment.new params[:payment]
The problem with your code was that you were doing
Payment.new(params[:id]). That's similar to calling something like
Payment.new(5) which doesn't really make sense.
Also, it's a good idea to include whatever code you think could be
related the problem. We'll be able to help you more quickly, as it's
far more likely to be an error in your code than a bug in Rails itself
Long wrote:
> I don't see a @payment.attributes = params[:payment] here so that the
> object is
> updated with the form attributes.
>
> HTH,
>
> Long
> www.edgesoft.ca
Long, that fixed the logjam! Now when I get back from my trip I'll back
out of my changes one by one till I'm back at TransDate with the proper
formatting, and see if anything breaks along the way.
I'm not quite clear on the differences between
@payment = Payment.new
Gives you an uninitialized instance
@payment = Payment.new(params[:id])
Gives you another uninitialized instance...I think.
@payment.attributes = params[:payment]
Updates @payment 'fields' with corresponding 'values' in the params hash
@payment = Payment.new(params[:payment])
Gives you a new and initialized (partial?) instance
Someone can correct if I am mistaken... I think knowing when to use each
just depends on the need and convenient.
and when you should use each of them. Is there a clear explanation
somewhere? I would like to use the most succinct method(s) possible, of
course.
Thanks, and Long, Max and Ryan, you are my heroes!
Hmm, I think Max and Ryan really deserve more credit.
I responded earlier, but realized that my response may not have been
quite detailed/nitpicky enough. So I'm going to nitpick your
response, if that's okay
> I'm not quite clear on the differences between
> @payment = Payment.new
Gives you an uninitialized instance
Gives you an instance with all its attributes initialized to default value.
> @payment = Payment.new(params[:payment])
Gives you a new and initialized (partial?) instance
Shortcut for Payment.new and Payment.attributes=. What I mean is that
you'll get an instance with attributes initialized to their default
values, and then any attributes in the hash will be assigned. So for
example, with a Person model that has name and age attributes..