

Imagine you've created a User model and, in the migration, ensured that the user's email address is unique.Vendor/bundle/ruby/2.5.0/gems/devise_token_auth-0.2.0/app/models/devise_token_auth/concerns/user.rb:211:in `build_auth_url' This is a hard problem to solve completely, but let's look at the low hanging fruit first. The issue here is that a database table in your application has a unique index on one or more fields and a transaction has been sent to the database that violates that index. This error message is specifically for PostgreSQL databases, but the ActiveRecord adapters for MySQL and SQLite will throw similar errors. ActiveRecord::RecordNotUnique: PG::UniqueViolation You can do so in a controller by skipping the authentication: class ApiController = "Comments couldn't be retrieved, please try again later."Įnd 5. You can turn off CSRF protection, but make sure you are whitelisting the endpoints you know don't need this kind of protection. You might be in this position if you are building an API for third party developers or if you expect to receive incoming webhooks from a service. If you expect to receive incoming POST requests to certain URLs in your application from third parties, you won’t want to block them on the basis of CSRF. Sometimes there are valid reasons to turn off the CSRF protection. const csrfToken = document.querySelector('').getAttribute('content') When making an Ajax request, read the meta tag content and add it to the headers as the X-CSRF-Token header. This prints out a meta tag that looks like this: Then add the route_not_found method to your ApplicationController: class ApplicationController of the document: Match '*unmatched', to: 'application#route_not_found', via: :all To do so, add the following at the bottom of your config/routes.rb file: do This method is suggested by the lograge project. If you aren’t interested in logging 404 errors caused by ActionController::RoutingError then you can avoid them by setting a catch all route and serving the 404 yourself. To fix this and allow Rails to serve static assets you need to add a line to your application’s config/environments/production.rb file: do If this is the case, the errors will look like this: ActionController::RoutingError (No route matches "///assets/application-eff78fd93759795a7be3aa21209b0bd2.css"): There is one common reason you might get an ActionController::RoutingError that is caused by your application and not by errant users: if you deploy your application to Heroku, or any platform that doesn’t allow you to serve static files, then you might find that your CSS and JavaScript doesn’t load. If that’s the case, you might find something like this in your logs: ActionController::RoutingError (No route matches "/wp-admin"): It may also be a malicious user or bot testing your application for common weaknesses. It may be caused by incorrect links pointing at or from within your application. Rails will log this and it will look like an error, but for the most part it is not the fault of your application. An ActionController::RoutingError means that a user has requested a URL that doesn’t exist within your application. We start with a classic of any web application, the Rails version of the 404 error. We'll provide example solutions based on Rails 5, but if you’re still using Rails 4 they should point you in the right direction. Let’s dig in and take a look at the errors in a bit more detail to see what might cause them in your production application. You’ve probably noticed some familiar faces in there already. We intentionally looked at the number of projects so that high-volume customers wouldn't overwhelm the data set with errors that are not relevant to most readers. To do this, we ranked errors by the number of projects experiencing them across different companies. We focused on the errors most likely to affect you and your users. This gives users a nice overview instead of an overwhelmingly big dump like you’d see in a log file. Basically, we group two errors if the second one is just a repeat of the first. We do this by grouping errors according to fingerprinting. Rollbar collects all the errors for each project and summarizes how many times each one occurred. If you avoid these "gotchas," it'll make you a better developer.īecause data is king, we collected, analyzed, and ranked the top 10 Ruby errors from Ruby on Rails applications.
#Undefined method map for nil nilclass how to
We’re going to show you what causes them and how to prevent them from happening. To give back to our community of developers, we looked at our database of thousands of projects and found the top 10 errors in Ruby on Rails projects.
