passing non-input values to db.

Hi Gurus,

can you please let me know how to pass values dat are not taken as input to user to db.The below are the details.

I have a model user (name:string email:string password:string role:string).

Now I dont want to take role from user.My view (html) does not contain input colum role.(the default role is normaluser).I want to assign it when the following conditions occur

if admin is creating the user the i have to assign moderator role to the user being created. I can check whos logged in now with say

current_user.admin?But how do i assign the moderator role to user role attribute



I don't really understand what you are asking. If you have a user in
@user then you can just say
@user.role = "admin" (or whatever is the appropriate string).
You could put this in the create action in the controller before the
record is saved or you could put it in a before filter in the model.


I think this could be done in user/create like

@user.role = “moderator” if current_user.admin?

yep I have done this and it works.Thanks to all.

regarding why i asked coz I was using devise and could not figure out where it should be changed in registration_controller.Atlast I got it.