js111 js111 - 1 year ago 81
SQL Question

Rails invalid date error

Im using this gem to setup a calendar in my app. Everything is working fine except the arrows that change the month.. Getting the following error:

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'




def show
@user = User.find(params[:id])
@friends = @user.friends.paginate(page: params[:page])
@date = params[:month] ? Date.parse(params[:month]) : Date.today


Started GET "/users/7?month=2012-06" for 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'

Answer Source

It is Date.parse("2012-06") causing the error.

If the date is not significant, you may try this: Date.parse("#{params[:month]}-01")