Guest User

Untitled

a guest
Jun 3rd, 2018
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.01 KB | None | 0 0
  1. ## users_controller.rb
  2. def admin_create
  3. @user = User.new(params[:user])
  4. @user.secret_question = "Are you human?"
  5. @user.secret_answer = "Yes"
  6. new_pass = User.random_string(10)
  7. @user.password = new_pass
  8. respond_to do |format|
  9. if @user.save
  10. name = @user.fname + " " + @user.lname
  11. flash[:notice] = "User " + name + " created successfully."
  12. Notifier.deliver_new_user(name, @user.email, new_pass, @user.secret_question, @user.secret_answer)
  13. format.html { redirect_to :action => :index }
  14. else
  15. flash[:notice] = "There was an error creating this user."
  16. end
  17. end
  18. end
  19.  
  20. ## add.html.rb
  21. <% content_for :javascript do %>
  22. <script type="text/javascript" src="/javascripts/jquery.js"></script>
  23. <script type="text/javascript">
  24. $(document).ready(function() {
  25. $("#courses").hide();
  26. $("#course_registration").click(function() {
  27. var type = document.getElementById("register_form_of_payment").value;
  28. if (type == "Now")
  29. {
  30. $('#courses').show('slow');
  31. return false;
  32. }
  33. else if (type == "Later")
  34. {
  35. $('#courses').hide('fast');
  36. return false;
  37. }
  38. });
  39. });
  40. </script>
  41. <% end %>
  42.  
  43. <h2 class="block">New User Creation Form</h2>
  44. <%= error_messages_for :user %>
  45.  
  46. <!-- Content unit - One column -->
  47. <div class="column1-unit">
  48. <div class="contactform">
  49. <% form_for :user, :url => { :action => "admin_create" } do |f| %>
  50. <p><label for="user_fname" class="left"><span class="star">*</span> First name:</label>
  51. <%= f.text_field :fname %></p>
  52. <p><label for="user_mi" class="left">Middle Initial:</label>
  53. <%= f.text_field :mi, :size => 5 %></p>
  54. <p><label for="user_lname" class="left"><span class="star">*</span> Last name:</label>
  55. <%= f.text_field :lname %></p>
  56. <p><label for="user_employer" class="left"><span class="star">*</span> Employer:</label>
  57. <%= f.text_field :employer %></p>
  58. <p><label for="user_job_title" class="left"><span class="star">*</span> Job Title:</label>
  59. <%= f.text_field :job_title %></p>
  60. <p><label for="user_address1" class="left"><span class="star">*</span> Work Address 1:</label>
  61. <%= f.text_field :address1 %></p>
  62. <p><label for="user_address2" class="left">Work Address 2:</label>
  63. <%= f.text_field :address2 %></p>
  64. <p><label for="user_city" class="left">City:</label>
  65. <%= f.text_field :city %></p>
  66. <p><label for="user_state" class="left"><span class="star">*</span> State:</label>
  67. <%= select("user", "state", State.find(:all).collect {|s| [s.state, s.id] }, { :include_blank => true }, :class => 'left') %></p>
  68. <p><label for="user_zip" class="left">Zip:</label>
  69. <%= f.text_field :zip %></p>
  70. <p><label for="user_phone1" class="left"><span class="star">*</span> Office Phone:</label>
  71. <%= f.text_field :phone1 %></p>
  72. <p><label for="user_phone2" class="left">Fax Number:</label>
  73. <%= f.text_field :phone2 %></p>
  74. <p><label for="user_email" class="left"><span class="star">*</span> Email:</label>
  75. <%= f.text_field :email %></p>
  76. <p><label for="user_admin">Make user an admin? <%= f.check_box :admin %></p>
  77. <br />
  78. <b>Your password will be sent to the e-mail address<br />entered above.</b><br /><br />
  79. <div align="center"><%= submit_tag 'Create User' %> <input type="reset"></div>
  80. <% end %>
  81. <br /><span class="star">*</span> <span style="font-size: 110%">Indicates required fields.</span>
  82. </div>
  83. </div>
  84. </div>
  85.  
  86. ## error
  87. NoMethodError in UsersController#admin_create
  88.  
  89. You have a nil object when you didn't expect it!
  90. The error occurred while evaluating nil.call
  91.  
  92. RAILS_ROOT: /home/tim/Code/slu
  93. Application Trace | Framework Trace | Full Trace
  94.  
  95. /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/mime_responds.rb:152:in `respond'
  96. /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/mime_responds.rb:150:in `each'
  97. /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/mime_responds.rb:150:in `respond'
  98. /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/mime_responds.rb:107:in `respond_to'
  99. app/controllers/users_controller.rb:42:in `admin_create'
  100. /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:1158:in `send'
  101. /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:1158:in `perform_action_without_filters'
  102. /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/filters.rb:697:in `call_filters'
  103. /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/filters.rb:689:in `perform_action_without_benchmark'
  104. /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'
  105. /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'
  106. /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/rescue.rb:199:in `perform_action_without_caching'
  107. /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/caching.rb:678:in `perform_action'
  108. /var/lib/gems/1.8/gems/activerecord-2.0.2/lib/active_record/connection_adapters/abstract/query_cache.rb:33:in `cache'
  109. /var/lib/gems/1.8/gems/activerecord-2.0.2/lib/active_record/query_cache.rb:8:in `cache'
  110. /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/caching.rb:677:in `perform_action'
  111. /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:524:in `send'
  112. /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:524:in `process_without_filters'
  113. /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/filters.rb:685:in `process_without_session_management_support'
  114. /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/session_management.rb:123:in `process'
  115. /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:388:in `process'
  116. /var/lib/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:489:in `load'
  117. /var/lib/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:489:in `load'
  118. /var/lib/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:342:in `new_constants_in'
  119. /var/lib/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:489:in `load'
  120. /var/lib/gems/1.8/gems/rails-2.0.2/lib/commands/servers/mongrel.rb:64
  121. /var/lib/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:496:in `require'
  122. /var/lib/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:342:in `new_constants_in'
  123. /var/lib/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:496:in `require'
  124. /var/lib/gems/1.8/gems/rails-2.0.2/lib/commands/server.rb:39
  125.  
  126. /usr/lib/ruby/1.8/benchmark.rb:293:in `measure'
  127. /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:171:in `handle_request'
  128. /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:115:in `dispatch'
  129. /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:126:in `dispatch_cgi'
  130. /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:9:in `dispatch'
  131. /usr/lib/ruby/1.8/mongrel/rails.rb:76:in `process'
  132. /usr/lib/ruby/1.8/mongrel/rails.rb:74:in `synchronize'
  133. /usr/lib/ruby/1.8/mongrel/rails.rb:74:in `process'
  134. /usr/lib/ruby/1.8/mongrel.rb:159:in `process_client'
  135. /usr/lib/ruby/1.8/mongrel.rb:158:in `each'
  136. /usr/lib/ruby/1.8/mongrel.rb:158:in `process_client'
  137. /usr/lib/ruby/1.8/mongrel.rb:285:in `run'
  138. /usr/lib/ruby/1.8/mongrel.rb:285:in `initialize'
  139. /usr/lib/ruby/1.8/mongrel.rb:285:in `new'
  140. /usr/lib/ruby/1.8/mongrel.rb:285:in `run'
  141. /usr/lib/ruby/1.8/mongrel.rb:268:in `initialize'
  142. /usr/lib/ruby/1.8/mongrel.rb:268:in `new'
  143. /usr/lib/ruby/1.8/mongrel.rb:268:in `run'
  144. /usr/lib/ruby/1.8/mongrel/configurator.rb:282:in `run'
  145. /usr/lib/ruby/1.8/mongrel/configurator.rb:281:in `each'
  146. /usr/lib/ruby/1.8/mongrel/configurator.rb:281:in `run'
  147. /usr/lib/ruby/1.8/mongrel_rails:129:in `run'
  148. /usr/lib/ruby/1.8/mongrel/command.rb:212:in `run'
  149. /usr/lib/ruby/1.8/mongrel_rails:282
  150. /usr/lib/ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'
  151. /usr/lib/ruby/1.8/rubygems/custom_require.rb:27:in `require'
  152. /usr/lib/ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'
  153. /usr/lib/ruby/1.8/rubygems/custom_require.rb:27:in `require'
  154. script/server:3
  155.  
  156. /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/mime_responds.rb:152:in `respond'
  157. /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/mime_responds.rb:150:in `each'
  158. /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/mime_responds.rb:150:in `respond'
  159. /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/mime_responds.rb:107:in `respond_to'
  160. app/controllers/users_controller.rb:42:in `admin_create'
  161. /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:1158:in `send'
  162. /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:1158:in `perform_action_without_filters'
  163. /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/filters.rb:697:in `call_filters'
  164. /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/filters.rb:689:in `perform_action_without_benchmark'
  165. /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'
  166. /usr/lib/ruby/1.8/benchmark.rb:293:in `measure'
  167. /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'
  168. /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/rescue.rb:199:in `perform_action_without_caching'
  169. /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/caching.rb:678:in `perform_action'
  170. /var/lib/gems/1.8/gems/activerecord-2.0.2/lib/active_record/connection_adapters/abstract/query_cache.rb:33:in `cache'
  171. /var/lib/gems/1.8/gems/activerecord-2.0.2/lib/active_record/query_cache.rb:8:in `cache'
  172. /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/caching.rb:677:in `perform_action'
  173. /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:524:in `send'
  174. /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:524:in `process_without_filters'
  175. /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/filters.rb:685:in `process_without_session_management_support'
  176. /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/session_management.rb:123:in `process'
  177. /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:388:in `process'
  178. /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:171:in `handle_request'
  179. /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:115:in `dispatch'
  180. /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:126:in `dispatch_cgi'
  181. /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:9:in `dispatch'
  182. /usr/lib/ruby/1.8/mongrel/rails.rb:76:in `process'
  183. /usr/lib/ruby/1.8/mongrel/rails.rb:74:in `synchronize'
  184. /usr/lib/ruby/1.8/mongrel/rails.rb:74:in `process'
  185. /usr/lib/ruby/1.8/mongrel.rb:159:in `process_client'
  186. /usr/lib/ruby/1.8/mongrel.rb:158:in `each'
  187. /usr/lib/ruby/1.8/mongrel.rb:158:in `process_client'
  188. /usr/lib/ruby/1.8/mongrel.rb:285:in `run'
  189. /usr/lib/ruby/1.8/mongrel.rb:285:in `initialize'
  190. /usr/lib/ruby/1.8/mongrel.rb:285:in `new'
  191. /usr/lib/ruby/1.8/mongrel.rb:285:in `run'
  192. /usr/lib/ruby/1.8/mongrel.rb:268:in `initialize'
  193. /usr/lib/ruby/1.8/mongrel.rb:268:in `new'
  194. /usr/lib/ruby/1.8/mongrel.rb:268:in `run'
  195. /usr/lib/ruby/1.8/mongrel/configurator.rb:282:in `run'
  196. /usr/lib/ruby/1.8/mongrel/configurator.rb:281:in `each'
  197. /usr/lib/ruby/1.8/mongrel/configurator.rb:281:in `run'
  198. /usr/lib/ruby/1.8/mongrel_rails:129:in `run'
  199. /usr/lib/ruby/1.8/mongrel/command.rb:212:in `run'
  200. /usr/lib/ruby/1.8/mongrel_rails:282
  201. /var/lib/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:489:in `load'
  202. /var/lib/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:489:in `load'
  203. /var/lib/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:342:in `new_constants_in'
  204. /var/lib/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:489:in `load'
  205. /var/lib/gems/1.8/gems/rails-2.0.2/lib/commands/servers/mongrel.rb:64
  206. /usr/lib/ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'
  207. /usr/lib/ruby/1.8/rubygems/custom_require.rb:27:in `require'
  208. /var/lib/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:496:in `require'
  209. /var/lib/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:342:in `new_constants_in'
  210. /var/lib/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:496:in `require'
  211. /var/lib/gems/1.8/gems/rails-2.0.2/lib/commands/server.rb:39
  212. /usr/lib/ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'
  213. /usr/lib/ruby/1.8/rubygems/custom_require.rb:27:in `require'
  214. script/server:3
  215.  
  216. Request
  217.  
  218. Parameters:
  219.  
  220. {"commit"=>"Create User",
  221. "authenticity_token"=>"8ed6997e1eff9ca5c167bc6cfaea333a83c06fb2",
  222. "user"=>{"address1"=>"123 Dreary Ln.",
  223. "city"=>"Beverly Hills",
  224. "address2"=>"not here",
  225. "zip"=>"90210",
  226. "job_title"=>"Tester",
  227. "admin"=>"0",
  228. "lname"=>"Test",
  229. "phone1"=>"123-456-7890",
  230. "mi"=>"A",
  231. "phone2"=>"213-209-1986",
  232. "employer"=>"ORA",
  233. "fname"=>"Bob",
  234. "state"=>"5",
  235. "email"=>"bob.t.user@thisisnotahost.com"}}
  236.  
  237. Show session dump
  238.  
  239. ---
  240. :csrf_id: 37b15f3632628d0585fc83d089768738
  241. :course_id: 1
  242. :user: !ruby/object:User
  243. attributes:
  244. address1: 124 Elm St.
  245. city: Big Rapids
  246. salt: 55X48YAqTE
  247. hashedpassword: 46caffbc5e671a640177fa9b1d3a678060c92de2
  248. address2: Desk 4
  249. zip: "49307"
  250. created_at: 2009-02-04 15:13:43
  251. job_title: Programmer
  252. hashedanswer: 2f3c803a5405588ae15642633e19ffe4cd73741c
  253. secret_question: City you were born in
  254. updated_at: 2009-02-04 15:15:33
  255. admin: "1"
  256. id: "5"
  257. lname: Hansen
  258. phone1: 231-123-4567
  259. mi: M
  260. phone2: 231-123-7890
  261. employer: ORA
  262. fname: Tim
  263. state: "23"
  264. email: thansen@orainc.com
  265. active: "1"
  266. attributes_cache: {}
  267.  
  268. courses:
  269. registers:
  270. flash: !map:ActionController::Flash::FlashHash
  271. :notice: There was an error creating this user.
  272.  
  273. Response
  274.  
  275. Headers:
  276.  
  277. {"cookie"=>[],
  278. "Cache-Control"=>"no-cache"}
Add Comment
Please, Sign In to add comment