HY 在我创建了用户的事件后,我试着看到它,但是我收到了一个错误 错误未定义方法`strftime'代表nil:NilClass
我不明白为什么我会收到此错误,因为在应用关联之前一切正常
show.html.erb
<p class="info">Evénement crée le <%= @calendar.published_on.strftime("%e %B, %Y") %>
10 <%= simple_format @calendar.description %>
11
12 <p>edit_calendar_path(:id)</p>
13 <%= link_to 'Edit', edit_calendar_path(@calendar) %> |
14 <%= link_to 'Back', user_calendars_path %> |
calendar.controler.rb
def index
#@content_calendars = @user.Calendar
@user = current_user
@content_calendars = @user.Calendar.all
@content_calendars_by_dates = @content_calendars.group_by(&:published_on)
@date = params[:date] ? Date.parse(params[:date]) : Date.today
end
def show
@user = current_user
# @calendar = @user.find_all_calendar_by()
# @tasks = @project.tasks.find_all_by_complete(false)
@calendar = @user.calendar.find(params[:id])
end
def new
@user = current_user
# @calendar = @user.build_calendar
@calendar = @user.calendar.build
end
def create
@user = current_user
@calendar = @user.calendar.build(params[:id])
#@calendar = @user.Calendar.new(params[:calendar])
if @calendar.save
#redirect_to calendar_path(@user)
redirect_to [@user,@calendar]
#, notice: "L evenement a ete cree"
else
render :new
end
end
show.html.erb
<% if user_signed_in? %>
<%= stylesheet_link_tag "index.css" %>
<%= stylesheet_link_tag "calendar.css" %>
<%= csrf_meta_tags %>
<div id="white-container"> <!-- Start White Container -->
<br/>
<div class="page-width"><!-- Start Page Width Content Box -->
<div class="contentbox">
<div id="calendar">New calendar</div><br />
<%= render 'form' %>
<%= link_to 'Back', user_calendars_path %>
<% else %>
<span>
<% flash[:info] = ''%>
</span>
<%= render 'devise/sessions/form' %>
<% end %>
</div>
</div>
</div>
_form.html.erb
<%= form_for([@user, @calendar]) do |f| %>
<% if @calendar.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@calendar.errors.count, "error") %> prohibited this calendar from being saved:</h2>
<ul>
<% @calendar.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :event %><br />
<%= f.text_field :event %>
</div>
<div class="field">
<%= f.label :published_on %><br />
<%= f.text_field :published_on, :size=>"10", :text_align=>"center" %>
</div>
<div class="field">
<%= f.label :description %><br />
<%= f.text_area :description, :rows => "10", :cols=> "30" %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>