I’m testing the 2.0 rails (after running into some gem problems to
upgrade it) and I really don’t know what’s wrong with this form. I
tried to keep it as simple as possible (maybe too simple that I forgot
something?).
Can someone point me the problem here?
def new @account = Account.new(params[:account])
if request.post? @account.balance = @account.initial_balance
if @account.save
redirect_to :action => “list”
else
redirect_to :action => “new”
end
end
end
I’m from Brazil so we write numbers like this 15.000,00 (comma as
decimal separator)…
I was inputing like this in the form and it didn’t work, when I
changed to this 15000.00 it worked.
But, there was nothing on the log giving me any tips for that…no SQL
error messages, no nothing…
This is the entry on the log…between the BEGIN the COMMIT there’s
nothing…as if there was no SQL to execute.
That’s kinda weird, right? Or is it the right behavior?
Processing AccountsController#new (for 127.0.0.1 at 2008-03-11
09:31:58) [POST]
Session ID:
BAh7BiIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNo
%0ASGFzaHsABjoKQHVzZWR7AA%3D
%3D–9e3a490edfbb816e5ed5e0d1573fbdd514229823
Parameters: {“commit”=>“OK”, “account”=>{“name”=>“Nova conta”,
“number”=>“5218 211455”, “currency_id”=>“1”,
“initial_balance”=>“1520,00”, “bank_id”=>“1”, “comment”=>“Sem
comentários”}, “action”=>“new”, “controller”=>“accounts”}
Account Columns (0.002612) SHOW FIELDS FROM accounts
SQL (0.000210) BEGIN
SQL (0.000146) COMMIT
Redirected to http://localhost:3000/accounts/new
Completed in 0.03512 (28 reqs/sec) | DB: 0.00297 (8%) | 302 Found
[http://localhost/accounts/new]
And one last thing, how do I change this number verification? I need
to “def validate” it myself?
or the validates_numericality_of works only for US like formating?
You may have posted the wrong fragment, or misunderstood the intention
of the controller. The ‘new’ method (shown above) is intended only to
return a blank form that you can fill out. The ‘create’ method should
be used to save the data for the first time.
As for the formatting, you may need to use a :before_validation
callback to massage the numeric into the ‘correct’ form.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.