Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @account = Account.find_by_subdomain(current_subdomain) # Consider putting this into a before_filter
- if request.post?
- user = User.create(params[:user]) do |u|
- o = [('a'..'z'),('0'..'9')].map{|i| i.to_a}.flatten # map of a-z0-9
- u.password = (0..5).map{ o[rand(o.length)] }.join # create random password from map
- u.user_type = 0 # You can override what the user wanted anyway, but attr_protected are better protections for this anyway
- u.account = @account
- u.contact = ''
- end
- if user.save
- redirect_to admin_users_path(user) # .id will be automatically called in this context, but you need to have this route defined... This method would be auto defined if you use resources in routes and follow Rails' RESTful scaffolding.
- end
- end
- in user.rb model
- class User
- # Whatever you already have in there, including validations and relationships
- attr_protected :user_type
- end
Add Comment
Please, Sign In to add comment