title: Ruby undefined method `strftime' for nil:NilClass
body: <p>I've only been working with Ruby for a short time and I've hit a wall today while working on a calendar to put requests on. I spent time searching through different undefinied method error documents on stackoverflow, the ruby guides, etc. as well as looking into strftime. I found a solution that partially solved my problem using try, but now it is not actually passing the strftime through to show on the request, even though the rails server is picking it up in the post. I can get to my calendar fine, and hit the new request button, fill out the form, but when I go to post that form the browsers gives me this:</p>
  
  <pre><code>undefined method `strftime' for nil:NilClass
  
  Extracted source (around line #3):
  
  1: &lt;h1&gt;&lt;%= @vacationrequest.request_name %&gt;&lt;/h1&gt;
  2: 
  3: &lt;p class="info"&gt;Requested For &lt;%= @vacationrequest.request_date.strftime("%B %e, %Y") %&gt;&lt;/p&gt;
  4: 
  5: &lt;%= simple_format @vacationrequest.message %&gt;
  6: 
  </code></pre>
  
  <p>And I get this error on the Rails server:</p>
  
  <pre><code>Started GET "/vacationrequests/1" for 127.0.0.1 at 2012-10-17 15:18:14 -0400
  Processing by VacationrequestsController#show as HTML
  Parameters: {"id"=&gt;"1"}
  ←[1m←[35mVacationrequest Load (0.0ms)←[0m SELECT "vacationrequests".* FROM "v
  acationrequests" WHERE "vacationrequests"."id" = ? LIMIT 1 [["id", "1"]]
  Rendered vacationrequests/show.html.erb within layouts/application (15.6ms)
  Completed 500 Internal Server Error in 31ms
  
  ActionView::Template::Error (undefined method strftime' for nil:NilClass):
  1: &lt;h1&gt;&lt;%= @vacationrequest.request_date %&gt;&lt;/h1&gt;
  2:
  3: &lt;p class="info"&gt;Requested For &lt;%= @vacationrequest.request_date.strftime(
  "%B %e, %Y") %&gt;&lt;/p&gt;
  4:
  5: &lt;%= simple_format @vacationrequest.message %&gt;
  6:
  app/views/vacationrequests/show.html.erb:3:inapp_views_vacationrequests_sho
  w_html_erb_217743956_18446544'
  </code></pre>
  
  <p>This is my show view:</p>
  
  <pre><code>&lt;h1&gt;&lt;%= @vacationrequest.request_name %&gt;&lt;/h1&gt;
  
  &lt;p class="info"&gt;Requested For &lt;%= @vacationrequest.request_date.strftime("%B %e, %Y") %&gt;&lt;/p&gt;
  
  &lt;%= simple_format @vacationrequest.message %&gt;
  
  &lt;p&gt;
    &lt;%= link_to "Edit Request", edit_vacationrequest_path(@vacationrequest) %&gt; |
    &lt;%= link_to "Back to Requests", vacationrequests_path %&gt;
  &lt;/p&gt;
  </code></pre>
  
  <p>and this is the _form that the user puts the request information into:</p>
  
  <pre><code>&lt;%= form_for @vacationrequest do |f| %&gt;
    &lt;% if @vacationrequest.errors.any? %&gt;
      &lt;div id="error_explanation"&gt;
        &lt;h2&gt;&lt;%= pluralize(@vacationrequest.errors.count, "error") %&gt; prohibited this request from being saved: if this continue to happens please email the error to alex@allsafeindustries.com&lt;/h2&gt;
        &lt;ul&gt;
        &lt;% @vacationrequest.errors.full_messages.each do |msg| %&gt;
          &lt;li&gt;&lt;%= msg %&gt;&lt;/li&gt;
        &lt;% end %&gt;
        &lt;/ul&gt;
      &lt;/div&gt;
    &lt;% end %&gt;
  
    &lt;div class="field"&gt;
      &lt;%= f.label :request_name %&gt;&lt;br /&gt;
      &lt;%= f.text_field :request_name %&gt;
    &lt;/div&gt;
    &lt;div class="field"&gt;
      &lt;%= f.label :request_date %&gt;&lt;br /&gt;
      &lt;%= f.text_field :request_date %&gt;
    &lt;/div&gt;
    &lt;div class="field"&gt;
      &lt;%= f.label :message %&gt;&lt;br /&gt;
      &lt;%= f.text_area :message %&gt;
    &lt;/div&gt;
    &lt;div class="actions"&gt;
      &lt;%= f.submit %&gt;
    &lt;/div&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>Finally here are my show and index methods in my controller:</p>
  
  <pre><code>  def index
      @vacationrequests = Vacationrequest.all
      @vacationrequests_by_date = @vacationrequests.group_by(&amp;:request_date)
      @date = params[:date] ? Date.parse(params[:date]) : Date.today
    end
  
    def show
      @vacationrequest = Vacationrequest.find(params[:id])
    end
  </code></pre>
  
  <p>Can anybody direct me to what is out of place or why this is nil? Thank you.</p>
  
  <p>In response to the answer here is what I am now getting from the server:</p>
  
  <pre><code>Started POST "/vacationrequests" for 127.0.0.1 at 2012-10-17 20:18:00 -0400
  Processing by VacationrequestsController#create as HTML
    Parameters: {"utf8"=&gt;"√", "authenticity_token"=&gt;"E1+xXP0pAIQpwMZruswxIZIrTZB3b
  c3NlW3iRv9OLqU=", "vacationrequest"=&gt;{"request_name"=&gt;"One more time", "request_
  date"=&gt;"10/31/2012", "message"=&gt;"Lucky number 7?"}, "commit"=&gt;"Create Vacationre
  quest"}
    ←[1m←[35m (0.0ms)←[0m  begin transaction
    ←[1m←[36mSQL (15.6ms)←[0m  ←[1mINSERT INTO "vacationrequests" ("created_at", "
  message", "request_date", "request_name", "updated_at") VALUES (?, ?, ?, ?, ?)←[
  0m  [["created_at", Thu, 18 Oct 2012 00:18:00 UTC +00:00], ["message", "Lucky nu
  mber 7?"], ["request_date", nil], ["request_name", "One more time"], ["updated_a
  t", Thu, 18 Oct 2012 00:18:00 UTC +00:00]]
    ←[1m←[35m (109.2ms)←[0m  commit transaction
  Redirected to http://localhost:3000/vacationrequests/7
  Completed 302 Found in 125ms (ActiveRecord: 124.8ms)
  
  
  Started GET "/vacationrequests/7" for 127.0.0.1 at 2012-10-17 20:18:01 -0400
  Processing by VacationrequestsController#show as HTML
    Parameters: {"id"=&gt;"7"}
    ←[1m←[36mVacationrequest Load (0.0ms)←[0m  ←[1mSELECT "vacationrequests".* FRO
  M "vacationrequests" WHERE "vacationrequests"."id" = ? LIMIT 1←[0m  [["id", "7"]
  ]
    Rendered vacationrequests/show.html.erb within layouts/application (15.6ms)
      Completed 500 Internal Server Error in 16ms
  
  ActionView::Template::Error (undefined method `strftime' for nil:NilClass):
      1: &lt;h1&gt;&lt;%= @vacationrequest.request_name %&gt;&lt;/h1&gt;
      2: &lt;%= debug @vacationrequest %&gt;
      3: &lt;p class="info"&gt;Requested For &lt;%= @vacationrequest.request_date.strftime(
  "%B %e, %Y") %&gt;&lt;/p&gt;
      4:
      5: &lt;%= simple_format @vacationrequest.message %&gt;
      6:
    app/views/vacationrequests/show.html.erb:3:in `_app_views_vacationrequests_sho
  w_html_erb___377763931_36688344'
  </code></pre>
  
  <p>I also used the view debug and checked my scheme and all of the attributes seemed to line up correctly.</p>
  
  <p>As for the request in the comments here is my Vacationrequest model:</p>
  
  <pre><code>class Vacationrequest &lt; ActiveRecord::Base
    attr_accessible :message, :request_name, :request_date
  end
  </code></pre>
  
  <p>Once again I can't thank you enough for your help.</p>
  
  <p>Here is the schema:</p>
  
  <pre><code>ActiveRecord::Schema.define(:version =&gt; 20121016194123) do
  
    create_table "vacationrequests", :force =&gt; true do |t|
      t.string   "request_name"
      t.date     "request_date"
      t.text     "message"
      t.datetime "created_at",   :null =&gt; false
      t.datetime "updated_at",   :null =&gt; false
    end
  end
  </code></pre>
  
  <p>and the create controller action code:</p>
  
  <pre><code>def create
    @vacationrequest = Vacationrequest.new(params[:vacationrequest])
    if @vacationrequest.save
      redirect_to @vacationrequest, notice: "Created Request!"
    else
      render :new
    end
  end
  </code></pre>
  
  <p>As I'm looking at this, is part of the problem my schema being plural and my controller being singular? Thanks again.</p>