开发者

form not saving to database in rails

I currently have a form:

<%= f.label(:price) %> <br/>
<%= f.text_field(:price, :value => number_to_currency(@object.price)) %>

I changed my migration from using float to using decimal:

change_column :object, :price, :decimal, :precision => 5, :scale => 2 

On my view, I called it using:

<%= @object.price %> 

For some reason, whenever I make a change to the form or in the console, it never saves the value and keeps it at $0.00 regardless of what i change it to开发者_开发技巧. In the view, it always shows up as '0.0'. I am not sure what the problem is.


Do you have a table named object or objects or is this just an example?

If not, check your price column to make sure the migration worked properly.

If you do have a proper column type in your table, check to see if you're using attr_accessible in the Object class (and that price is included).

Also, if you are using Object as your class name, you may have some other issues here and I'd advise against it.

EDIT number_to_currencymay prepend a $ in front of your cost, make sure you're entering your price without any currency before it or else I believe this would also result in 0.0 (can't parse decimal '$123.00', but can parse '123.00'

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜