Advertisement
Guest User

Untitled

a guest
Jul 31st, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.76 KB | None | 0 0
  1. See the below for the error info ....
  2.  
  3. "nil is not a symbol"
  4. /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/validations.rb:296:in `send'
  5. /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/validations.rb:296:in `validates_each'
  6. /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/validations.rb:514:in `validates_uniqueness_of'
  7. #{RAILS_ROOT}/app/models/user.rb:25
  8. #{RAILS_ROOT}/app/controllers/application.rb:29:in `check_authorization'
  9. /usr/local/bin/mongrel_rails:18
  10.  
  11.  
  12. in user.rb
  13.  
  14. # Fun easy validation
  15. validates_uniqueness_of :username, :on => :createuser, :message => "is already in the system."
  16. validates_uniqueness_of :username, :on => :updateuser, :message => "is already in the system."
  17. validates_uniqueness_of :email, :on => :createuser, :message => "is already in the system."
  18. validates_uniqueness_of :email, :on => :updateuser, :message => "is already in the system."
  19.  
  20. validates_format_of :username, :with => /^[A-Za-z][A-Za-z0-9\-\_]{2,39}$/, :message => "can only consist of letters, numbers, -, and _"
  21. validates_format_of :first_name, :with => /^[A-Za-z0-9\-\s]*$/, :message => "can only consist of letters, numbers, -, and _"
  22. validates_format_of :middle_name, :with => /^[A-Za-z0-9\-\s]*$/, :message => "can only consist of letters, numbers, -, and _"
  23. validates_format_of :last_name, :with => /^[A-Za-z0-9\-\s]*$/, :message => "can only consist of letters, numbers, -, and _"
  24. validates_format_of :email, :with => /^([^@\s] )@((?:[-a-z0-9] \.) [a-z]{2,})$/, :message => "is not valid."
  25.  
  26. validates_length_of :email, :maximum=> 100, :message => "may only be a maximum of 100 charactars."
  27. validates_length_of :ip_address, :maximum => 15, :message => "is too long (format: ###.###.###.###)."
  28. validates_length_of :first_name, :maximum => 40, :allow_nil => true
  29. validates_length_of :middle_name, :maximum => 40, :allow_nil => true
  30. validates_length_of :last_name, :maximum => 40, :allow_nil => true
  31.  
  32. validates_presence_of :username, :email, :ipaddr
  33.  
  34. validates_numericality_of :confirmed, :on => :createuser
  35. validates_numericality_of :confirmed, :on => :updateuser
  36.  
  37.  
  38.  
  39.  
  40.  
  41. the newuser.rhtml
  42.  
  43. <h2><span>Create User</span></h2>
  44.  
  45. <%= start_form_tag({:action => "createuser", :controller => "admin"}, {:onSubmit => "Element.show('ident_spinner');" }) %>
  46.  
  47. <%= render :partial => 'form_user' %>
  48.  
  49. <%= end_form_tag %>
  50.  
  51. the _form_user.rhtml
  52.  
  53. <script>keepFlashAlive = true;</script>
  54.  
  55. <!--[form:user]-->
  56. <dl>
  57.  
  58. <dt>Username</dt>
  59. <dd>
  60. <%= text_field 'user', 'username' %>
  61. </dd>
  62.  
  63. <dt>Password</dt>
  64. <dd>
  65. <%= password_field 'post', 'password_first' %>
  66. </dd>
  67.  
  68. <dt>Re-type Password</dt>
  69. <dd>
  70. <%= password_field 'post', 'password_second' %>
  71. </dd>
  72.  
  73. <dt>Email Address</dt>
  74. <dd>
  75. <%= text_field 'user', 'email' %>
  76. </dd>
  77.  
  78. <dt>First Name</dt>
  79. <dd>
  80. <%= text_field 'user', 'first_name' %>
  81. </dd>
  82.  
  83. <dt>Middle Name</dt>
  84. <dd>
  85. <%= text_field 'user', 'middle_name' %>
  86. </dd>
  87.  
  88. <dt>Last Name</dt>
  89. <dd>
  90. <%= text_field 'user', 'last_name' %>
  91. </dd>
  92.  
  93. <br /><br />
  94. <dd>
  95. <input type='submit' value='Submit' class='primary' />
  96. <%= image_tag('/images/admin/spinner_mac.gif', :align => 'absmiddle', :border=> 0, :id=>'ident_spinner', :style=>'display: none;' ) %>
  97. </dd>
  98.  
  99. </dl>
  100. <!--[eoform:user]-->
  101.  
  102. <%= params.inspect %>
  103.  
  104.  
  105. the admin controller ....
  106. def newuser
  107. @user = User.new()
  108. end
  109.  
  110. def createuser
  111. @user = User.new(params[:user])
  112. @user.password = params[:post][:password_first]
  113. @user.password_hash
  114. @user.password_salt
  115. if @user.save
  116. flash[:notice] = "The user was successfully created."
  117. redirect_to :action => "listusers"
  118. else
  119. render :action => "newuser"
  120. end
  121. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement