# Whats wrong with my form? (rails 2.0)

**URL:** <https://www.ruby-forum.com/t/whats-wrong-with-my-form-rails-2-0/131564>\
**Category:** Rails\
**Created:** [March 11, 2008, 12:28pm UTC](https://www.ruby-forum.com/t/whats-wrong-with-my-form-rails-2-0/131564 "2008-03-11T12:28:54Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![cldwalker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@cldwalker](https://www.ruby-forum.com/u/cldwalker)\
**Post date:** [March 11, 2008, 12:28pm UTC](https://www.ruby-forum.com/t/whats-wrong-with-my-form-rails-2-0/131564/1 "2008-03-11T12:28:54Z")

</div>

Hi everyone,

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?

The view:

\<% form\_for :account do %\>

| Nome: | \<%= text\_field :account, :name %\> |
| Banco: | \<%= select("account", "bank\_id", Bank.find(:all).map {|b| [b.name, b.id]}) %\> |
| Número: | \<%= text\_field :account, :number %\> |
| Saldo inicial: | \<%= text\_field :account, :initial\_balance %\> |
| Moeda: | \<%= select("account", "currency\_id", Currency.find(:all).map {|c| [c.name, c.id]}) %\> |
| Comentários: | \<%= text\_field :account, :comment %\> |
| \<%= submit\_tag "OK" %\> |

\<% end %\>

The action:

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 would appreciate some help here.

Thank you,

Gabriel H.

---

<div class="post-metadata">

**Author:** ![cldwalker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@cldwalker](https://www.ruby-forum.com/u/cldwalker)\
**Post date:** [March 11, 2008, 12:36pm UTC](https://www.ruby-forum.com/t/whats-wrong-with-my-form-rails-2-0/131564/2 "2008-03-11T12:36:35Z")

</div>

Hi Gabriel,

Could please post the problem that you are getting ?

On Tue, Mar 11, 2008 at 8:28 AM, Gabriel H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> \<%= select("account", "currency\_id", \<% end %\> redirect\_to :action =\> "new" Gabriel H. \>

–  
Rui

> **[ruivaldo\_](https://ruivaldo.wordpress.com/)**
>
> psicanalista de sistemas

“Rubi? Aquela novela do SBT?”  
~ Carla Perez sobre Ruby

“Em Python, tudo Ã© objeto, alÃ©m de lindo e maravilhoso.”  
~ Caetano Veloso sobre Python

“SDD → Skol Driven Development is the new age of computing.”  
~ Martin F.

---

<div class="post-metadata">

**Author:** ![cldwalker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@cldwalker](https://www.ruby-forum.com/u/cldwalker)\
**Post date:** [March 11, 2008, 12:48pm UTC](https://www.ruby-forum.com/t/whats-wrong-with-my-form-rails-2-0/131564/3 "2008-03-11T12:48:33Z")

</div>

Oh, sorry, the problem is it’s not saving the data.  
With rails 1.2.4 (using the form\_tag instead) it worked, now its not  
saving.

I figure its something wrong I’m doing in the view cuz the action is  
quite simple right?

And I’m new to Rails so I don’t know where to look for system error  
messages for the problem.

---

<div class="post-metadata">

**Author:** ![cldwalker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@cldwalker](https://www.ruby-forum.com/u/cldwalker)\
**Post date:** [March 11, 2008, 1:16pm UTC](https://www.ruby-forum.com/t/whats-wrong-with-my-form-rails-2-0/131564/4 "2008-03-11T13:16:52Z")

</div>

in your app in the log folder you’ll find the file development.log

with rake log:clear you can clear that (can’t damage anything)

after every call to controller/action you’ll get the whole set of  
params used for that call and all error messages in that file

check if the view hands in any data as params

with:  
logger.info “text #{vars}”

you can write debug messages directly to that file from your controller

---

<div class="post-metadata">

**Author:** ![cldwalker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@cldwalker](https://www.ruby-forum.com/u/cldwalker)\
**Post date:** [March 11, 2008, 1:15pm UTC](https://www.ruby-forum.com/t/whats-wrong-with-my-form-rails-2-0/131564/5 "2008-03-11T13:15:51Z")

</div>

We still need way more information than what you’re giving us.

Is it erroring when it saves? What URL is it generating? Is it even  
going to  
the create/update page?

The more information you give us, the greater the chance of us being  
able to  
solve your problem.

---

<div class="post-metadata">

**Author:** ![cldwalker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@cldwalker](https://www.ruby-forum.com/u/cldwalker)\
**Post date:** [March 11, 2008, 1:44pm UTC](https://www.ruby-forum.com/t/whats-wrong-with-my-form-rails-2-0/131564/6 "2008-03-11T13:44:21Z")

</div>

I found the problem.

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](http://localhost:3000/accounts/new)  
Completed in 0.03512 (28 reqs/sec) | DB: 0.00297 (8%) | 302 Found  
[[http://localhost/accounts/new](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?

Thanks for the help.

On Mar 11, 9:22 am, Mark B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![cldwalker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@cldwalker](https://www.ruby-forum.com/u/cldwalker)\
**Post date:** [March 11, 2008, 1:22pm UTC](https://www.ruby-forum.com/t/whats-wrong-with-my-form-rails-2-0/131564/7 "2008-03-11T13:22:02Z")

</div>

Gabriel H. wrote:

> \<% form\_for :account do %\>

#form\_for will scope the account object saving you from referring to it  
in every entry. Use:

\<% form\_for(@account) do |f| %\>

Then the entries become:

> \<%= text\_field :account, :name %\>

\<%= f.text\_field :name %\>

> \<%= select("account", "bank\_id", Bank.find(:all).map {|b| [b.name, b.id]}) %\>

I haven’t fully checked, but I don’t think #select is scoped, so leave  
this as it is.

> \<%= text\_field :account, :number %\>

\<%= f.text\_field :number %\>

> \<%= text\_field :account, :initial\_balance %\>

\<%= f.text\_field :initial\_balance %\>

> \<%= text\_field :account, :comment %\>

\<%= f.text\_field :comment %\>

> \<%= submit\_tag "OK" %\>

\<%= f.submit “OK” %\>

If this fails, send the errors from your log file along with the  
parameters in the log being sent to your #new action.

---

<div class="post-metadata">

**Author:** ![cldwalker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@cldwalker](https://www.ruby-forum.com/u/cldwalker)\
**Post date:** [March 11, 2008, 5:05pm UTC](https://www.ruby-forum.com/t/whats-wrong-with-my-form-rails-2-0/131564/8 "2008-03-11T17:05:35Z")

</div>

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.
