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@googlegroups.com.
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.

Search Discussions

  • Colin Law at Nov 3, 2011 at 9:54 am

    On 3 November 2011 09:09, newrails user 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
    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.

    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@googlegroups.com.
    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.
  • Kevin at Nov 3, 2011 at 11:45 pm
    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@googlegroups.com.
    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.
  • Newrails user at Nov 4, 2011 at 10:26 am
    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 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@googlegroups.com.
    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.
    --
    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@googlegroups.com.
    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.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedNov 3, '11 at 9:09a
activeNov 4, '11 at 10:26a
posts4
users3
websiterubyonrails.org
irc#RubyOnRails

3 users in discussion

Newrails user: 2 posts Kevin: 1 post Colin Law: 1 post

People

Translate

site design / logo © 2022 Grokbase