ruby on rails - Help on Inserting a record to the db -
i insert record db based on values of querystring parameters, @ minute have scaffold methods , works, takes values @ in new method, when sumbit button clicked, inserted db.
how can 'skip' clicking of button, inserted in new method?
code:
@book = book.new(params[:book]) @book = book.new({:user_id=>session[:user_id], :author=>session['test']}) respond_to |format| if @book.save format.html { redirect_to(@book, :notice => 'book created.') } format.xml { render :xml => @book, :status => :created, :location => @book } else format.html { render :action => "new" } format.xml { render :xml => @book.errors, :status => :unprocessable_entity } end end
put in action want save automatically:
@book = book.new(params[:book]) @book.save
some thing might want add: save if if params[:book] set:
unless params[:book].blank? @book = book.new(params[:book]) @book.save end
also think of error handling. if book not stored?
Comments
Post a Comment