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

  • Home
  • SEARCH
  • 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 792763
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T22:02:35+00:00 2026-05-14T22:02:35+00:00

Quick question. Here is my code: #routes map.resources :customers, :has_many => [:addresses, :matchings] map.connect

  • 0

Quick question. Here is my code:

#routes
map.resources :customers, :has_many => [:addresses, :matchings]
map.connect ":controller/:action/:id"

#url path:
http://127.0.0.1:3000/customers/index/3

#customers controller
def index
  @customer = Customer.find(params[:id])
end

#customers view/index.html.erb
...
<%= @customer.name %>
...

Error: undefined method `name’ for nil:NilClass.

Here’s my reasoning. The parameter :id is coming from my url path (i.e. we’re looking for customer #3 in the above path). @customer should find that array easily, then @customer.name should produce the name, but apparently @customer is blank. Why?

I assume the problem is that I’m not producing an array in my controller?

——UPDATE——

Hi Larry, thanks very much for the comments.

What I mean by ‘index’ is actually a home page that customers will hit when they log in to the site. (I also have separate logins for other users like employers and they go to their own index). I’m currently using ‘list’ as a list of customers and ‘show’ for one individual… is there a better way?

Second and MOST important: the logs are not giving me the answer to the fundamental problem, which is the inability to render the page.

Processing CustomersController#index (for 127.0.0.1 at 2010-05-16 16:56:19) [GET]
Parameters: {"action"=>"index", "id"=>"10", "controller"=>"customers"}
...
[4;36;1mCustomer Load (2.0ms)[0m   [0;1mSELECT * FROM "customers" WHERE ("customers"."id" = 10) [0m
[4;35;1mMatching Load (24.0ms)[0m   [0mSELECT * FROM "matchings" WHERE ("matchings".customer_id = 10) [0m
Completed in 153ms (View: 18, DB: 26) | 200 OK [http://127.0.0.1/customers/index/10]

——UPDATE #2 (last!) ——

I read through all of your comments and they have helped me not only make progress on my problem but also learn more about how the pieces fit together. For that, thanks everyone.

Alex is right – my routes are not lining up how they need to. I created a new action in my customer controller called Home. This is the customer’s home base when they log in (it doesn’t display info about one customer so it probably shouldn’t be show, and it isn’t a list so shouldn’t be index or list).

Rake routes # ...gives me a list of routes that does NOT include home. Why?

Second, if the route displayed has, for example:

:action => "home"
/customers # (instead of what I need, '/customers/:id')

what do I have to do to change that route to accept an :id?

  • 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-05-14T22:02:36+00:00Added an answer on May 14, 2026 at 10:02 pm

    Have a look at rake routes. The index action for a resource doesn’t match an id. I suspect Rails doesn’t even put the id into params for index action. Like Ryan said, you should be using the show action for that, and the URL for the show action will be http://localhost:3000/customers/3.

    If you’re going to use RESTful resources, you probably want to get rid of the default map.connect ":controller/:action/:id" route.

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

Sidebar

Related Questions

Another quick question here, I have this code: string sa[6] = { Fort Sumter,
Here's a quick question I've been banging my head against today. I'm trying to
Quick question, If I want to document some code on a basic HTML and
A quick question here about the new WCF Ria services beta: If I do
just a quick question here. How can I add an image to my UIViewController.
Quick question I currently have a small bit of code that is pulling comments
Quick question here, I'm using Visual Studio to create an Outlook add-in. I've created
Here's a quicky question. Which method name makes the most sense for an Objective-C
Quick question. What do you think, I have a few sites that use a
Quick question: Would it be a good or a bad idea to implement my

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.