Mysql Rails无效日期错误
我正在使用gem在我的应用程序中设置日历。除了改变月份的箭头外,一切正常。。获取以下错误:Mysql Rails无效日期错误,mysql,ruby-on-rails,ruby-on-rails-3,Mysql,Ruby On Rails,Ruby On Rails 3,我正在使用gem在我的应用程序中设置日历。除了改变月份的箭头外,一切正常。。获取以下错误: ArgumentError in UsersController#show invalid date Rails.root: /Users/nelsonkeating/Desktop/ReminDeal Application Trace | Framework Trace | Full Trace app/controllers/users_controller.rb:13:in `show' Re
ArgumentError in UsersController#show
invalid date
Rails.root: /Users/nelsonkeating/Desktop/ReminDeal
Application Trace | Framework Trace | Full Trace
app/controllers/users_controller.rb:13:in `show'
Request
Parameters:
{"month"=>"2012-06",
"id"=>"7"}
用户\u controller.rb
def show
@user = User.find(params[:id])
@friends = @user.friends.paginate(page: params[:page])
@date = params[:month] ? Date.parse(params[:month]) : Date.today
end
控制台:
Started GET "/users/7?month=2012-06" for 127.0.0.1 at 2012-05-29 21:30:04 -0700
Processing by UsersController#show as HTML
Parameters: {"month"=>"2012-06", "id"=>"7"}
User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = 7 LIMIT 1
User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", "7"]]
Completed 500 Internal Server Error in 33ms
ArgumentError (invalid date):
app/controllers/users_controller.rb:13:in `show'
导致错误的原因是日期解析(“2012-06”)
如果日期不重要,您可以尝试以下操作:date.parse(“#{params[:month]}-01”)
导致错误的是date.parse(“2012-06”)
如果日期不重要,可以尝试以下操作:date.parse(“#{params[:month]}-01”)
希望这对你有帮助
希望这对你有帮助
It is cause due to improper format of the date, the date format is either "%Y-%m-%d" or"%d-%m-%Y" since you have just pass the parameter i.e.
{"month"=>"2012-06", "id"=>"7"}
you should send the parameter
{"month"=>"2012-06-27", "id"=>"7"}
you should send the date also
I had the same problem and solve by adding day in the date parameter.