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 Thanks, S -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 3 November 2011 09:09, newrails user <newror.user-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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 > attributeI 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. Colin -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
I think this could be done in user/create like @user.role = "moderator" if current_user.admin? -- kevin Sent with Sparrow (http://www.sparrowmailapp.com/?sig) On Thursday, November 3, 2011 at 5:09 PM, newrails user wrote:> moderator-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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. Thanks, siva On Thu, Nov 3, 2011 at 3:27 PM, kevin <rubyonrailsx-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I think this could be done in user/create like > > @user.role = "moderator" if current_user.admin? > > -- > kevin > Sent with Sparrow <http://www.sparrowmailapp.com/?sig> > > On Thursday, November 3, 2011 at 5:09 PM, newrails user wrote: > > *moderator* > > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.