Guest User

Untitled

a guest
Mar 7th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. View:
  2. <% form_for(:user, :url => domain_users_path) do |f| %>
  3. <fieldset>
  4. <label class="field-username">new email &#42;<input type="text" name="username" value="" /></label><span class="secondary_label">@<%=h @domain.domain %></span>
  5. <label class="field-password">password &#42;<input type="password" name="password" value="" /></label>
  6. <label class="field-name">full name &#42;<input type="text" name="first_name" value="" /></label>
  7. <%= submit_tag "Create" %>
  8. </fieldset>
  9. <% end %>
  10.  
  11.  
  12. controller:
  13. def create
  14. @user = User.new(params[:user])
  15. @domain = Domain.find params[:domain_id]
  16. respond_to do |format|
  17. if @user.save
  18. flash[:notice] = 'User was successfully created.'
  19. format.html { redirect_to domain_url(@domain.id) }
  20. else
  21. format.html { render :action => "new" }
  22. end
  23. end
  24. end
  25.  
  26. model:
  27. class User < ActiveRecord::Base
  28. belongs_to :domain
  29.  
  30. def before_save
  31. self.homedir = "/home/vmail"
  32. self.quota = "0"
  33. self.maildir = "/home/vmail/#{@domain.id}/#{:username}/.maildir/"
  34. :full_email
  35. end
  36.  
  37. attr_accessor :username
  38.  
  39. def password=(p)
  40. self.clear = p
  41. end
  42. def password
  43. clear
  44. end
  45.  
  46. def full_email=(username)
  47. self.email = "#{username}@#{@domain.id}"
  48. end
  49. def full_email
  50. email
  51. end
  52.  
  53. end
Add Comment
Please, Sign In to add comment