How to set a default value?

Hello,

I have a price field that I validate of numbers.
How can I default a 0.0 value?

Regards,

Frank R.
removed_email_address@domain.invalid

If you set the default in the database, ActiveRecord should
automatically
use it.

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 B. wrote:

Rails mailing list
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails

Regards,

Frank R.
removed_email_address@domain.invalid

Hello Frank !

2005/12/6, Frank R. removed_email_address@domain.invalid:

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 !

On Dec 6, 2005, at 9:11 PM, Francois B. wrote:

http://lists.rubyonrails.org/mailman/listinfo/rails
Thank you…

Regards,

Frank R.
removed_email_address@domain.invalid