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 8674907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:49:18+00:00 2026-06-12T19:49:18+00:00

This is the relevant part of my _form.html.erb <%= form_for(@score) do |f| %> <%

  • 0

This is the relevant part of my _form.html.erb

<%= form_for(@score) do |f| %>
  <% if @score.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@score.errors.count, "error") %> prohibited this score from being saved:</h2>
      <ul>
      <% @score.errors.full_messages.each do |msg| %>
        <li><%= msg %></li>
      <% end %>
      </ul>
    </div>
  <% end %>

    <div class="field">
      <%= f.label :client_id %><br />
      <%= f.select :client_id, @clients.collect { |c| [c.name, c.id] }, {:include_blank => 'None'} %>
    </div>  

  <div class="field">
    <%= f.label :firm_size %><br />
    <%= f.text_field :firm_size %>
  </div>
    .
    .
    .
  <div class="actions">
    <%= f.submit %>
  </div>
<% end %>

This partial works when I have a generic for creating a Score and there is a collection of clients passed in through the controller via clients.

The issue is when there is just one client record….say for a URL like:
myapp.com/client/6/scores/new/

Given that I have a client_id in the params, it gives me a nil error:

undefined method `collect' for nil:NilClass

How do I solve this for one single @client record?

  • 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-12T19:49:19+00:00Added an answer on June 12, 2026 at 7:49 pm

    It looks like you’re using nested resources, so in the case of myapp.com/client/6/scores/new/ your new method in your ScoreController should be called.

    In this method (or in a before filter), I’m assuming you have a line that’s something like:

    @client = Client.find(params[:client_id])
    

    Now, if you want to use your partial the way yours is built, you either have to ensure, that there’s an object that responds to the method collect (i.e. an array) with the name of @clients or you could go ahead and rewrite your partial and split it up in if sections or so…

    The error message you get basically means, that when ScoreController#new method’s being rendered there’s no object called @clients therefore it’s nil, and the NilClass has no method collect

    So I would just do the following in your ScoreController#new method:

    # get your single client
    @client = Client.find(params[:client_id])
    
    # and simply put it in an array with the name your partial uses
    @clients = [ @client ]
    

    Now, I’m not sure that’s an elegant solution, but it should keep you going…

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

Sidebar

Related Questions

This is the relevant part of my code (I am trying to add a
How Do You Turn On Parenthesis Matching in Visual Studio 2005? This is relevant
I tried to find this in the relevant RFC, IETF RFC 3986 , but
I have 2 entities in CoreData (which are relevant to this). Let's call them
I'm specifically referring to JavaScript anonymous function but this could be relevant to other
Folks. I trust that the community will see this as a relevant question. My
Though it's on the edge of programming questions, I think this is still relevant
This is what I have in mind: Can anyone point out some relevant resources?
NB: This question has been extensively edited to make it more relevant, for completeness
this is really doing my nut..... all relevant PHP Output scripts set headers (in

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.