KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
In my controller controller, I have use Date.new to create a date object to be passed in my ActiveRecord. end_range = Date.new(params[:year].to_i, params[:month].to_i, params[:day].to_i).end_of_day.to_formatted_s(:db) The problem with this above is that if a user tried to change the parameters in the URL manually, such as entering 40 for the day param, the Date.new fails (as expected). However, I would rather not have a 500 error if a user typed in something like that, but instead a 404 error (because you will never actually be able a record with a day of 40 ). I tried various conditionals ( if and unless statements) to raise ActiveRecord::RecordNotFound if that fails, but it returns the 500 error before running the conditional (and therefor never returning a 404). Does anybody know a better way to handle that, or a way to allow the Date.new to fail more gracefully so that the conditional statement can run?
Tags (comma-separated)
Save Edits
Cancel