Skip to content

Instantly share code, notes, and snippets.

@burtlo
Created February 17, 2013 06:39
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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.

@steveklabnik
Copy link

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

@timpriwe
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
Copy link

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

@didymus707
Copy link

Logging out I am getting unknown action "The action 'destroy' could not be found for AuthorSessionsController", anyone knows what is going on?

@nestor-c
Copy link

nestor-c commented May 6, 2020

@didymus707 I haven't completed the authorization portion yet but it seems like your AuthorSessions Controller doesn't have a destroy action defined. I'm guessing your logout button calls a destroy method which rails tries to find within your AuthorSessions controller but it can't find it. I know I used a lot of the same terminology as your error but I hope I helped.

@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