Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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.

@steveklabnik

This comment has been minimized.

Copy link

steveklabnik commented Feb 18, 2013

It appears that redirect_to article_path(@article) goes to /articles/ now.

@timpriwe

This comment has been minimized.

Copy link

timpriwe commented Feb 9, 2017

After logging in, i automaticly land on the authors list, do you know how to fix it?

@loumarven

This comment has been minimized.

Copy link

loumarven commented Feb 11, 2019

After logging in, i automaticly land on the authors list, do you know how to fix it?

In case you still need the fix, in my app, I changed the "redirect_back_or_to" to "redirect_to" in app/controllers/author_sessions_contoller.rb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.