Hi Nathan,

Instead of this:

  fundingtarget :dollars, :precision => 12, :scale => 2, :default => 0

You should try:

 fundingtarget Dollars, :precision => 12, :scale => 2, :default => 0

Warm regards,
Ignacio



El 19-08-2015 a las 15:15, Nathan Peters escribió:
> From the rich type docs on the website and reading the list archives I
> have made the following changes to create a Dollars rich type:
> 
> In a new file: app/models/dollars.rb
> 
> *class Dollars < DelegateClass(BigDecimal)
>   COLUMN_TYPE = :decimal
>   HoboFields.register_type(:dollars, self)
> end*
> 
> Two tag definitions in application.dryml
> 
> *<def tag="view" for="Dollars">$<%= number_to_currency(this) %></def>
> 
> <def tag="input" for="Dollars" attrs="name">
>     $ <%= text_field_tag(name, this, attributes) %>
> </def>
> *
> And the following field in my Project model:
> 
> *fundingtarget :dollars, :precision => 12, :scale => 2, :default => 0*
> 
> 
> So I run "rails s". And look at my project show page: there is no "$"
> near my fundingtarget field. I change the value to 250. It is
> successful, and the SQL is:
> 
> UPDATE "projects" SET "fundingtarget" = ?, "updated_at" = ? WHERE
> "projects"."id" = 2  [["fundingtarget",
> #<BigDecimal:51fd548,'0.25E3',9(18)>], ["updated_at", Wed, 19 Aug 2015
> 05:42:39 UTC +00:00]]
> 
> Now I remove the "$" from the Dollars view tag definition. Refresh the
> page and there is now a "$" in my funding target field ($250 is shown).
> I edit and change the field to 300 and get the following error:
> 
> TypeError: can't cast Dollars to decimal: UPDATE "projects" SET
> "fundingtarget" = ?, "updated_at" = ? WHERE "projects"."id" = 2
> 
> And the SQL was:
> 
> UPDATE "projects" SET "fundingtarget" = ?, "updated_at" = ? WHERE
> "projects"."id" = 2  [["fundingtarget",
> #<BigDecimal:5564e20,'0.3E3',9(18)>], ["updated_at", Wed, 19 Aug 2015
> 05:45:09 UTC +00:00]]
> 
> So I go back to my view tag for Dollars and re-add the "$". Save and
> view the show page. Now there are *two* dollar signs ($$250 is shown!).
> 
> Once again I try an edit, changing the value to 300 and get the same
> TypeError as before.
> 
> The only way to avoid errors is to stop and restart the server at which
> point I can view and update, but no dollars sign is shown regardless of
> the starting content of the Dollars view tag. Any change/save of this
> tag (even removing the "$"!) results in a "$" being shown on the page,
> but errors on update.
> 
> Stumped,
> Nathan
> 
> -- 
> You received this message because you are subscribed to the Google
> Groups "Hobo Users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to [email protected]
> <mailto:[email protected]>.
> To post to this group, send email to [email protected]
> <mailto:[email protected]>.
> Visit this group at http://groups.google.com/group/hobousers.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups "Hobo 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/hobousers.
For more options, visit https://groups.google.com/d/optout.

Reply via email to