当我单击按钮时出现错误,错误提示为 nil:NilClass 的未定义方法“strftime”
当我调试我的应用程序时,我看到了一些奇怪的东西
tarted POST "/users/2/calendars" for 127.0.0.1 at 2013-05-24 19:44:25 +0200
Processing by CalendarsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"8l0+IDaC+tAHdQi+yvpnWEJRHrR8hNwBA3zgaSBoovQ=", "calendar"=>{"event"=>"aze", "published_on"=>"2013-05-07", "description"=>"rrrrrrr"}, "commit"=>"Create Calendar", "user_id"=>"2"}
User Load (0.2ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 2 LIMIT 1
(0.1ms) BEGIN
SQL (0.2ms) INSERT INTO `calendars` (`created_at`, `description`, `event`, `published_on`, `updated_at`, `user_id`) VALUES ('2013-05-24 17:44:26', NULL, NULL, NULL, '2013-05-24 17:44:26', 2)
(79.8ms) COMMIT
Redirected to http://127.0.0.1:3000/users/2/calendars/39
Completed 302 Found in 93ms (ActiveRecord: 80.3ms)
cache: [GET /users/2/calendars/39] miss
为什么他不接受我的可变事件,发表的描述我不明白。我错过了什么?
日历模型
class Calendar < ActiveRecord::Base
attr_accessible :event, :published_on, :description, :user_id
belongs_to :user#, :foreign_key => :user_id
end
用户模型
has_many :calendar#, :foreign_key => :user_id
accepts_nested_attributes_for :calendar
#attr_accessible :calendar_id
end
日历控制器
def index
@user = current_user
#@content_calendars = @user.Calendar
@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.calendar.new
#@calendar = @user.calendar.build
end
# GET /calendars/1/edit
def edit
@user = current_user
@calendar = @user.Calendar.find(params[:id])
end
# POST /calendars
# POST /calendars.json
def create
@user = current_user
@calendar = @user.calendar.new(params[:current_user])
#@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
# PUT /calendars/1
# PUT /calendars/1.json
def update
@user = current_user
@calendar = @user.Calendar.find(params[:id])
if @calendar.update_attributes(params[:id])
redirect_to [@user, @calendar]#, notice: "L article a ete mis a jour"
else
render :edit
end
end
# DELETE /calendars/1
# DELETE /calendars/1.json
def destroy
@user = current_user
@calendar.destroy
respond_to do |format|
format.html { redirect_to calendars_url }
format.json { head :no_content }
end
end
private
def find_user
@user = current_user
#@user = User.first
#@user ||= User.find(session[:user_id]) if session[:user_id]
#findession[:user_id])
end
再次感谢您的帮助