Hello, I have a price field that I validate of numbers. How can I default a 0.0 value? Regards, Frank Rocco farocco-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org
If you set the default in the database, ActiveRecord should automatically use it. On Tue, 6 Dec 2005, Frank Rocco wrote:> Hello, > > I have a price field that I validate of numbers. > How can I default a 0.0 value?
i''m developing a simple content management app in rails where users can create content in the browser. i''d like to give them the ability to "tag" content with multiple keywords. so on the form where they are creating/editing content there is a text field called tag_tags[] where they can type in space-seperated tags. i have 3 tables: pages, tags, and pages_tags. i pre-populated tags with 3 records just to test things out. if a user enters a pre-existing tag in the field, a record gets added to the pages_tags table appropriately. however, if the user enters a tag that doesn''t already exist, i''d like to add a record to tags, and then add a record to pages_tags with the new tag_id. here''s my update method in pages_controller.rb ---------------------- def update @page = Page.find(params[:id]) a = @params[:tag_tags].to_s ta = a.split('' '') ta.each{|t| tg = Tag.find(:all, :conditions => ["tag = ?", t]) @page.tags << tg } if @page.update_attributes(params[:page]) flash[:notice] = ''Page was successfully updated.'' redirect_to :action => ''list'', :id => @page, :section_id => @page.section_id else render :action => ''edit'' end end ------------------------ i''ve tried doing a if tg.nil? @nt = Tag.create(t) @nt.save @page.tags << nt end but that doesn''t add a record to the tags table. any ideas? i am only a few weeks into rails so i am probably missing something obvious! thanks! steve
thanks, that works. Anyway to do it in code? On Dec 6, 2005, at 7:28 PM, Ken Bowley wrote:> If you set the default in the database, ActiveRecord should > automatically use it. > > On Tue, 6 Dec 2005, Frank Rocco wrote: > >> Hello, >> >> I have a price field that I validate of numbers. >> How can I default a 0.0 value? > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/railsRegards, Frank Rocco farocco-H+0wwilmMs3R7s880joybQ@public.gmane.org
Hello Frank ! 2005/12/6, Frank Rocco <farocco@verizon.net>:> Anyway to do it in code?class Account < ActiveRecord::Base def after_initialize self.balance = 0.0 end end See the callbacks section in the Rails API documentation: http://api.rubyonrails.com/classes/ActiveRecord/Callbacks.html Bye ! -- François Beausoleil http://blog.teksol.info/ _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
On Dec 6, 2005, at 9:11 PM, Francois Beausoleil wrote:> Hello Frank ! > > 2005/12/6, Frank Rocco <farocco-H+0wwilmMs3R7s880joybQ@public.gmane.org>: >> Anyway to do it in code? > > class Account < ActiveRecord::Base > def after_initialize > self.balance = 0.0 > end > end > > See the callbacks section in the Rails API documentation: > http://api.rubyonrails.com/classes/ActiveRecord/Callbacks.html > > Bye ! > -- > François Beausoleil > http://blog.teksol.info/ > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/railsThank you.... Regards, Frank Rocco farocco-H+0wwilmMs3R7s880joybQ@public.gmane.org