Topic: How Do I instantiate an object instance without using form

I want to be able to create an instance of a model and save it to the database without using any form.
I want to hardcode the values and when the user clicks a button it will automatically add to the database with the session key.
I do not want the user to be able to modify the data. My main problem is where do I put it?
Thanks

Re: How Do I instantiate an object instance without using form

I would use the create method already present, and then !create the object. For example:

def create
   @variable1 = 233
   @variable2 = 'hello'
   @obj = Object.new(:v1 => @variable1, :v2 => @variable2)
   if @obj.save
       flash[:success]="Yay new obj created"
       redirect_to root_path
   else
       flash[:error]=":-) epic fail"
       render new
   end
end

and then you could call it from the view with a form or button, example:

<%= button_to 'Create Object', object_path, :method => :post %>

Re: How Do I instantiate an object instance without using form

Or you could use the create (or create!) method that ActiveRecord already provides.  Arguments are the same as new but it saves as well as instanciates.