Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## users_controller.rb
- def admin_create
- @user = User.new(params[:user])
- @user.secret_question = "Are you human?"
- @user.secret_answer = "Yes"
- new_pass = User.random_string(10)
- @user.password = new_pass
- respond_to do |format|
- if @user.save
- name = @user.fname + " " + @user.lname
- flash[:notice] = "User " + name + " created successfully."
- Notifier.deliver_new_user(name, @user.email, new_pass, @user.secret_question, @user.secret_answer)
- format.html { redirect_to :action => :index }
- else
- flash[:notice] = "There was an error creating this user."
- end
- end
- end
- ## add.html.rb
- <% content_for :javascript do %>
- <script type="text/javascript" src="/javascripts/jquery.js"></script>
- <script type="text/javascript">
- $(document).ready(function() {
- $("#courses").hide();
- $("#course_registration").click(function() {
- var type = document.getElementById("register_form_of_payment").value;
- if (type == "Now")
- {
- $('#courses').show('slow');
- return false;
- }
- else if (type == "Later")
- {
- $('#courses').hide('fast');
- return false;
- }
- });
- });
- </script>
- <% end %>
- <h2 class="block">New User Creation Form</h2>
- <%= error_messages_for :user %>
- <!-- Content unit - One column -->
- <div class="column1-unit">
- <div class="contactform">
- <% form_for :user, :url => { :action => "admin_create" } do |f| %>
- <p><label for="user_fname" class="left"><span class="star">*</span> First name:</label>
- <%= f.text_field :fname %></p>
- <p><label for="user_mi" class="left">Middle Initial:</label>
- <%= f.text_field :mi, :size => 5 %></p>
- <p><label for="user_lname" class="left"><span class="star">*</span> Last name:</label>
- <%= f.text_field :lname %></p>
- <p><label for="user_employer" class="left"><span class="star">*</span> Employer:</label>
- <%= f.text_field :employer %></p>
- <p><label for="user_job_title" class="left"><span class="star">*</span> Job Title:</label>
- <%= f.text_field :job_title %></p>
- <p><label for="user_address1" class="left"><span class="star">*</span> Work Address 1:</label>
- <%= f.text_field :address1 %></p>
- <p><label for="user_address2" class="left">Work Address 2:</label>
- <%= f.text_field :address2 %></p>
- <p><label for="user_city" class="left">City:</label>
- <%= f.text_field :city %></p>
- <p><label for="user_state" class="left"><span class="star">*</span> State:</label>
- <%= select("user", "state", State.find(:all).collect {|s| [s.state, s.id] }, { :include_blank => true }, :class => 'left') %></p>
- <p><label for="user_zip" class="left">Zip:</label>
- <%= f.text_field :zip %></p>
- <p><label for="user_phone1" class="left"><span class="star">*</span> Office Phone:</label>
- <%= f.text_field :phone1 %></p>
- <p><label for="user_phone2" class="left">Fax Number:</label>
- <%= f.text_field :phone2 %></p>
- <p><label for="user_email" class="left"><span class="star">*</span> Email:</label>
- <%= f.text_field :email %></p>
- <p><label for="user_admin">Make user an admin? <%= f.check_box :admin %></p>
- <br />
- <b>Your password will be sent to the e-mail address<br />entered above.</b><br /><br />
- <div align="center"><%= submit_tag 'Create User' %> <input type="reset"></div>
- <% end %>
- <br /><span class="star">*</span> <span style="font-size: 110%">Indicates required fields.</span>
- </div>
- </div>
- </div>
- ## error
- NoMethodError in UsersController#admin_create
- You have a nil object when you didn't expect it!
- The error occurred while evaluating nil.call
- RAILS_ROOT: /home/tim/Code/slu
- Application Trace | Framework Trace | Full Trace
- /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/mime_responds.rb:152:in `respond'
- /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/mime_responds.rb:150:in `each'
- /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/mime_responds.rb:150:in `respond'
- /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/mime_responds.rb:107:in `respond_to'
- app/controllers/users_controller.rb:42:in `admin_create'
- /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:1158:in `send'
- /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:1158:in `perform_action_without_filters'
- /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/filters.rb:697:in `call_filters'
- /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/filters.rb:689:in `perform_action_without_benchmark'
- /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'
- /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'
- /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/rescue.rb:199:in `perform_action_without_caching'
- /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/caching.rb:678:in `perform_action'
- /var/lib/gems/1.8/gems/activerecord-2.0.2/lib/active_record/connection_adapters/abstract/query_cache.rb:33:in `cache'
- /var/lib/gems/1.8/gems/activerecord-2.0.2/lib/active_record/query_cache.rb:8:in `cache'
- /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/caching.rb:677:in `perform_action'
- /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:524:in `send'
- /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:524:in `process_without_filters'
- /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/filters.rb:685:in `process_without_session_management_support'
- /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/session_management.rb:123:in `process'
- /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:388:in `process'
- /var/lib/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:489:in `load'
- /var/lib/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:489:in `load'
- /var/lib/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:342:in `new_constants_in'
- /var/lib/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:489:in `load'
- /var/lib/gems/1.8/gems/rails-2.0.2/lib/commands/servers/mongrel.rb:64
- /var/lib/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:496:in `require'
- /var/lib/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:342:in `new_constants_in'
- /var/lib/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:496:in `require'
- /var/lib/gems/1.8/gems/rails-2.0.2/lib/commands/server.rb:39
- /usr/lib/ruby/1.8/benchmark.rb:293:in `measure'
- /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:171:in `handle_request'
- /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:115:in `dispatch'
- /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:126:in `dispatch_cgi'
- /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:9:in `dispatch'
- /usr/lib/ruby/1.8/mongrel/rails.rb:76:in `process'
- /usr/lib/ruby/1.8/mongrel/rails.rb:74:in `synchronize'
- /usr/lib/ruby/1.8/mongrel/rails.rb:74:in `process'
- /usr/lib/ruby/1.8/mongrel.rb:159:in `process_client'
- /usr/lib/ruby/1.8/mongrel.rb:158:in `each'
- /usr/lib/ruby/1.8/mongrel.rb:158:in `process_client'
- /usr/lib/ruby/1.8/mongrel.rb:285:in `run'
- /usr/lib/ruby/1.8/mongrel.rb:285:in `initialize'
- /usr/lib/ruby/1.8/mongrel.rb:285:in `new'
- /usr/lib/ruby/1.8/mongrel.rb:285:in `run'
- /usr/lib/ruby/1.8/mongrel.rb:268:in `initialize'
- /usr/lib/ruby/1.8/mongrel.rb:268:in `new'
- /usr/lib/ruby/1.8/mongrel.rb:268:in `run'
- /usr/lib/ruby/1.8/mongrel/configurator.rb:282:in `run'
- /usr/lib/ruby/1.8/mongrel/configurator.rb:281:in `each'
- /usr/lib/ruby/1.8/mongrel/configurator.rb:281:in `run'
- /usr/lib/ruby/1.8/mongrel_rails:129:in `run'
- /usr/lib/ruby/1.8/mongrel/command.rb:212:in `run'
- /usr/lib/ruby/1.8/mongrel_rails:282
- /usr/lib/ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'
- /usr/lib/ruby/1.8/rubygems/custom_require.rb:27:in `require'
- /usr/lib/ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'
- /usr/lib/ruby/1.8/rubygems/custom_require.rb:27:in `require'
- script/server:3
- /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/mime_responds.rb:152:in `respond'
- /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/mime_responds.rb:150:in `each'
- /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/mime_responds.rb:150:in `respond'
- /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/mime_responds.rb:107:in `respond_to'
- app/controllers/users_controller.rb:42:in `admin_create'
- /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:1158:in `send'
- /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:1158:in `perform_action_without_filters'
- /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/filters.rb:697:in `call_filters'
- /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/filters.rb:689:in `perform_action_without_benchmark'
- /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'
- /usr/lib/ruby/1.8/benchmark.rb:293:in `measure'
- /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'
- /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/rescue.rb:199:in `perform_action_without_caching'
- /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/caching.rb:678:in `perform_action'
- /var/lib/gems/1.8/gems/activerecord-2.0.2/lib/active_record/connection_adapters/abstract/query_cache.rb:33:in `cache'
- /var/lib/gems/1.8/gems/activerecord-2.0.2/lib/active_record/query_cache.rb:8:in `cache'
- /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/caching.rb:677:in `perform_action'
- /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:524:in `send'
- /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:524:in `process_without_filters'
- /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/filters.rb:685:in `process_without_session_management_support'
- /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/session_management.rb:123:in `process'
- /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:388:in `process'
- /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:171:in `handle_request'
- /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:115:in `dispatch'
- /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:126:in `dispatch_cgi'
- /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:9:in `dispatch'
- /usr/lib/ruby/1.8/mongrel/rails.rb:76:in `process'
- /usr/lib/ruby/1.8/mongrel/rails.rb:74:in `synchronize'
- /usr/lib/ruby/1.8/mongrel/rails.rb:74:in `process'
- /usr/lib/ruby/1.8/mongrel.rb:159:in `process_client'
- /usr/lib/ruby/1.8/mongrel.rb:158:in `each'
- /usr/lib/ruby/1.8/mongrel.rb:158:in `process_client'
- /usr/lib/ruby/1.8/mongrel.rb:285:in `run'
- /usr/lib/ruby/1.8/mongrel.rb:285:in `initialize'
- /usr/lib/ruby/1.8/mongrel.rb:285:in `new'
- /usr/lib/ruby/1.8/mongrel.rb:285:in `run'
- /usr/lib/ruby/1.8/mongrel.rb:268:in `initialize'
- /usr/lib/ruby/1.8/mongrel.rb:268:in `new'
- /usr/lib/ruby/1.8/mongrel.rb:268:in `run'
- /usr/lib/ruby/1.8/mongrel/configurator.rb:282:in `run'
- /usr/lib/ruby/1.8/mongrel/configurator.rb:281:in `each'
- /usr/lib/ruby/1.8/mongrel/configurator.rb:281:in `run'
- /usr/lib/ruby/1.8/mongrel_rails:129:in `run'
- /usr/lib/ruby/1.8/mongrel/command.rb:212:in `run'
- /usr/lib/ruby/1.8/mongrel_rails:282
- /var/lib/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:489:in `load'
- /var/lib/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:489:in `load'
- /var/lib/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:342:in `new_constants_in'
- /var/lib/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:489:in `load'
- /var/lib/gems/1.8/gems/rails-2.0.2/lib/commands/servers/mongrel.rb:64
- /usr/lib/ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'
- /usr/lib/ruby/1.8/rubygems/custom_require.rb:27:in `require'
- /var/lib/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:496:in `require'
- /var/lib/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:342:in `new_constants_in'
- /var/lib/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:496:in `require'
- /var/lib/gems/1.8/gems/rails-2.0.2/lib/commands/server.rb:39
- /usr/lib/ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'
- /usr/lib/ruby/1.8/rubygems/custom_require.rb:27:in `require'
- script/server:3
- Request
- Parameters:
- {"commit"=>"Create User",
- "authenticity_token"=>"8ed6997e1eff9ca5c167bc6cfaea333a83c06fb2",
- "user"=>{"address1"=>"123 Dreary Ln.",
- "city"=>"Beverly Hills",
- "address2"=>"not here",
- "zip"=>"90210",
- "job_title"=>"Tester",
- "admin"=>"0",
- "lname"=>"Test",
- "phone1"=>"123-456-7890",
- "mi"=>"A",
- "phone2"=>"213-209-1986",
- "employer"=>"ORA",
- "fname"=>"Bob",
- "state"=>"5",
- "email"=>"bob.t.user@thisisnotahost.com"}}
- Show session dump
- ---
- :csrf_id: 37b15f3632628d0585fc83d089768738
- :course_id: 1
- :user: !ruby/object:User
- attributes:
- address1: 124 Elm St.
- city: Big Rapids
- salt: 55X48YAqTE
- hashedpassword: 46caffbc5e671a640177fa9b1d3a678060c92de2
- address2: Desk 4
- zip: "49307"
- created_at: 2009-02-04 15:13:43
- job_title: Programmer
- hashedanswer: 2f3c803a5405588ae15642633e19ffe4cd73741c
- secret_question: City you were born in
- updated_at: 2009-02-04 15:15:33
- admin: "1"
- id: "5"
- lname: Hansen
- phone1: 231-123-4567
- mi: M
- phone2: 231-123-7890
- employer: ORA
- fname: Tim
- state: "23"
- email: thansen@orainc.com
- active: "1"
- attributes_cache: {}
- courses:
- registers:
- flash: !map:ActionController::Flash::FlashHash
- :notice: There was an error creating this user.
- Response
- Headers:
- {"cookie"=>[],
- "Cache-Control"=>"no-cache"}
Add Comment
Please, Sign In to add comment