Skip to content

Instantly share code, notes, and snippets.

@edavis10
Created April 22, 2009 19:11
Show Gist options
  • Save edavis10/99990 to your computer and use it in GitHub Desktop.
Save edavis10/99990 to your computer and use it in GitHub Desktop.
Changing or creating a User's Role in Redmine
# Changing the current user's Role
def change_role(role, project)
# User logged in?
if User.current.logged?
# Will get the existing Member object or a new one if the User isn't yet a Member of the project
member = Member.find_or_initialize_by_user_id_and_project_id(User.current, project.id)
member.role = role
member.project = project
if member.save
# Successfully saved
else
# Had an error saving. Should inform the user and recover.
end
end
end
change_role(Project.find(params[:project_id]), Role.find(42))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment