Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7974709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:27:13+00:00 2026-06-04T08:27:13+00:00

In Rails 3.2.2, I want to setup custom URLs (using State 2 digit :abbr,

  • 0

In Rails 3.2.2, I want to setup custom URLs (using State 2 digit :abbr, instead of the default by :id)

Reading google results and stackoverflow pages, I’ve come up with this:

Routes

match 'cars/:abbr' => 'states#show', :as => 'state_abbr'

Model

def to_param
  abbr
end

Controller

@state = State.find_by_abbr(params[:id])

The state#show page is throwing out errors (undefined method `fullname’ for nil:NilClass), because the routing does not seem to be finding the abbr in the model.

Running rake routes, I get:

 root  /                    states#index
 state_abbr  /cars/:abbr(.:format) states#show

Thanks for your help

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T08:27:14+00:00Added an answer on June 4, 2026 at 8:27 am

    You want to use params[:abbr] not params[:id]. If you want to use :id change your route to be 'cars/:id' instead of 'cars/:abbr'

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Rails 3, and Ubuntu. I want to change the default Rails SQLite3
I want to setup a 'Create Account' page. The gems I'm using are: rails
I want to setup a rails app on heroku that is part of a
I've got a RESTful setup for the routes in a Rails app using text
My setup: Rails 2.3.10, Ruby 1.8.7 This is a simple question but I want
I have a Rails 3 app with authentication setup using Devise with the registerable
instead of the standard capistrano deploy flow for a rails app, I just want
My setup: Rails 3.0.9, Ruby 1.9.2 I want to check the gem version for
I am using Ruby on Rails 3.0.9 and I am trying to setup the
For my Rails project, I use custom code to setup my database before each

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.