Three Things I Learned This Week - December 02 2016
- thoughtbot put out a nice form linting tool to help diagnose common form issues. There’s a bit of overlap between this and our common ADA toolset, but it’s a nice secondary check to make sure forms are implemented well.
- I’ve recently had the need to combine url parameters. For example say I have already performed a search - say
/search?q=termand the use then chooses to switch locales -
/?locale=es. Ideally the search term would be preserved and the final result would be something like
/search?q=term&locale=es. This can easily be done with the
url_formethod and merging the existing params:
- If a user hits a url such as /posts/123, but there is no post with id: 123, Rails will correctly display a 404 response. But why is this? The error raised by Active Record is an ActiveRecord::RecordNotFound, how does that become a 404 response? The answer is in the
ActionDispatch::ExceptionWrapper.rescue_responsesmethod. If you run this method in your console, you’ll see the mapping:
ActiveRecord::RecordNotFound returns a
:not_found response, which according to the guides is the 404 status code.