hi, This should be really simple, but i cant seem to find the answer anywhere!! In my _form.rhtml I have the following text field, how can I define a default value? <%= text_field ''purchaseorder'', ''number'' %> -- Posted via http://www.ruby-forum.com/.
Back in your controller action, do: def new @purchaseorder.number = "some number" end -- Posted via http://www.ruby-forum.com/.
<%= text_field ''purchaseorder'', ''number'', :value => "some value" %> but like Bryan said, if you have an instance variable named purchaseorder, rails should automatically fill in the default value with the attributes of this variable. Mike On 5/12/06, Bryan Duxbury <bryan.duxbury@gmail.com> wrote:> Back in your controller action, do: > > def new > @purchaseorder.number = "some number" > end > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Bryan Duxbury wrote:> Back in your controller action, do: > > def new > @purchaseorder.number = "some number" > endthanks :) -- Posted via http://www.ruby-forum.com/.
Possibly a better way to accomplish this is to set a default on the model object when it is instantiated: class PurchaseOrder < ActiveRecord::Base def initialize(attributes = nil) super self.number = 123 unless number? end end -Jonathan. On 5/13/06, ss <scott@boxuk.com> wrote:> Bryan Duxbury wrote: > > Back in your controller action, do: > > > > def new > > @purchaseorder.number = "some number" > > end > > thanks :) > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >