insert data to the databse..

how can i insert data to the database from any controller

Assuming you want to add a user from an arbitrary controller... You
would instantiate the new user in an action ('new_user') and save it
to the database (and raise validation errors) from a create action
(here called 'create_user')

class ArbitraryController < ActionController::Base

  def index
    @users = User.find(:all)

  def new_user
    @user =

  def create_user
    @user =[:user])
    redirect_to :action => 'index'


You would have to define the routes in your routes.rb file like:

map.connect '/user/new', :controller => 'arbitrary', :action =>