Skip to content

Instantly share code, notes, and snippets.

@burtlo
Created February 17, 2013 06:39
Show Gist options
  • Save burtlo/4970471 to your computer and use it in GitHub Desktop.
Save burtlo/4970471 to your computer and use it in GitHub Desktop.
Some common errors after finishing the Jumpstart Lab Blogger tutorial a number of times.

Rake Routes

Problem

Running rake routes with a new rails application displays no information.

Solution

Rake routes should display to the user:

  • No routes have been defined
  • Recommend to the user that they define routes within their routes file (i.e. config/routes.rb)
  • Provide additional documentation about defining routes
  • Provide links to documentation about defining routes

Rake Routes should display headers above their data columns

Problem

Rake routes displays output in a columized format. The layout of this information is not common knowledge to new Rails users.

Solution

Rake routes displays header information for each column.

HELPER PREFIXES | HTTP VERB | URL PATTERN | CONTROLLER#ACTION

Delete Path

Problem

Defining a delete link is far different then every other link the user usually generates while working with Rails.

Solution

Ideally the user would be able to use a helper method

link_to "Delete", delete_article_path(article)

I realize that this would likely be a difficult helper method to create and make work with the current infrastructure as all trailing parameters are used to define the additional, necessary parameters.

Missing Partial Form Error Message

Problem

When the user sends the render message with a partial form name and the partial form is missing. The current error message tells the user to define a file with a path that will not actually work with partial forms as it is missing the '_' file prefix.

Solution

The error message should tell the user to define a form with the correct path that includes the initial underscore.

Partial Form Declaration

Problem

Partial forms can use a shorter syntax simply calling the render method with a string.

<%= render "articles/comment" %>

A user is required to use the hash syntax when they want to include additional parameters:

<%= render partial: "articles/comment", collection: @article.comments  %>

Users that attempt to provide parameters to partial forms with the first version will receive an error.

<%= render "articles/comment", collection: @article.comments  %>

Solution

Allow the following version to also work:

<%= render "articles/comment", collection: @article.comments  %>

redirect_to with an unsaved model

Problem

A user defines a controller action which attempts to save the item that they are building. If they add validations to the model and that model fails validations when they send:

redirect_to article_path(@article)

An error is generating that it could not find a path:

No route matches {:action=>"show", :controller=>"articles", :id=>#<Article id: nil, title: "", body: "", created_at: nil, updated_at: nil>}

Solution

The user is presented with a better error message that tells the user the path could not be viewed because the object did had a nil id value.

@didymus707
Copy link

Thanks @nestor-c, I figured it out, it was the before_filter method in my AuthorSessions Controller that was causing the issue

@Pandenok
Copy link

Pandenok commented Oct 3, 2020

before_filter has been deprecated in Rails 5.0 and removed in 5.1.
Use before_action instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment