DEV Community

Cover image for Common errors when learning rails!!!!
Edward Mendoza
Edward Mendoza

Posted on

Common errors when learning rails!!!!

Most common errors in rails

Hi everybody, this is my second post and since we already completed the rails module in Flatiron School, i would like to talk about some of the most common errors that i face when i was learning and working with labs.

Number 1

NoMethodError: undefined method '[]' for nil:NilClass
I face this error a lot, when i was working with forms and i was using another model collection to create a drop-down, and basically tell us that we are trying to use a square bracket notation to read a property from an object, but the object is missing, or nil, in my case was because usually i forgot to get the instance variable in the action, lets say in the create action and the validation to save failed, then render the new form again, and is when the error came.

Number 2

ActionController::RoutingError
This error basically is telling us that the user made a request to a specific URL that doesn't exist in our routes file, so when the router try to match with a controller action, i will throw the error.

Number 3

ActionController::ParameterMissing
This error is related to the strong parameters and the way that we construct the params, probably we miss to add the :key for the params hash.

Number 4 & last one

ActionView::Template::Error: undefined local variable or method
This error basically means that we are missing the view for the action that was call, and the easy fix is by only create the file under the folder.

Thats all for this post, hope is useful :)!

Discussion (0)