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)
end
def new_user
@user = User.new
end
def create_user
@user = User.new(params[:user])
@user.save
redirect_to :action => ''index''
end
end
You would have to define the routes in your routes.rb file like:
map.connect ''/user/new'', :controller =>
''arbitrary'', :action =>
''new_user''
HTH
On Jun 23, 5:25 am, Soutom
<soutom.dh...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> how can i insert data to the database from any controller
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---