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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:15:13+00:00 2026-05-20T10:15:13+00:00

Rails 2.3.5 I have a view displaying ’employee’ records in a table where each

  • 0

Rails 2.3.5

I have a view displaying ’employee’ records in a table where each table row haas a check_box_tag to select that (row) employee record (the table is inside a form_tag). The checkbox is passing an array of employee numbers to a method but I also need it to pass some of the other information from the record (first_name, last_name, etc) in the params.

Orignally this looked like (just passing an param with an array of employee numbers)

<% @employee_search.each do |e| %>
 <td><%= check_box_tag 'selected_subordinates[]', e.employee_number %></td>
 <td><%= e.employee_number %></td>
 <td><%= e.first_name %></td>
 <td><%= e.last_name %></td>
 ...
<% end %>

I’m not sure this was right, but I thought I should pass the entire record (‘e’) in the param:

<% @employee_search.each do |e %>
 <td><%= check_box_tag 'selected_subordinates[]', e %></td>
 <td><%= e.employee_number %></td>
 <td><%= e.first_name %></td>
 <td><%= e.last_name %></td>
 ...
<% end %>

The param array now looks like:

"selected_subordinates"=>["#<Employee:0xa946970>", "#<Employee:0xa946910>", "#<Employee:0xa9468b0>"]

I thought at this point I would be fine and just itterate through the objects in the param array referring to the record fields, but got an undefined method error:

params[:selected_subordinates].each do |s|
  puts s.last_name
end

undefined method `last_name' for "#<Employee:0xa946970>":String

I started wondering if for some reason the entire model object was passed instead of just one record from the object. But, trying [0].last_name resulted in a different error.

params[:selected_subordinates].each do |s|
  puts s.last_name
end

undefined method `last_name' for 35:Fixnum

Maybe I should have been using the fields I need to build an array for the param – so the param would be an array of arrays? I haven’t had any luck so far trying to search for example of what to do when you need to setup a param array made of arrays, or pass a single model object record (and refer to it).

Thank You – Much Appreciated!

  • 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-20T10:15:14+00:00Added an answer on May 20, 2026 at 10:15 am

    When you used e as the param, Rails was converting e to a String and passing that (you can’t pass an object in an HTML form, right? Just values). When you saw "#<Employee:0xa946970>" in your params hash, it wasn’t an Employee object, but instead a String with the contents of #<Employee:0xa946970> (which is what you get if you called .to_s on an Employee object).

    Passing the ID gets you on the right track, but once you have the ID, you should look up the Employee with that ID from the database.

    params[:selected_subordinates].each do |s|
      employee = Employee.find(s)
      puts employee.last_name
    end
    

    Of course, this loads them one at a time, so if you have a lot of checkboxes you could end up generating a large number of queries. You can also use the find method to find multiple objects based on an array of IDs:

    employees = Employee.find(params[:selected_subordinates])
    employees.each do |e|
      puts e.last_name
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am beginner in rails. I have view that i try to print inside
In my rails project I have a presenter method that has a helper view
I have a Rails view that produces a HTML report based on the user
I have rails application that has two view ports that uses the same data.
In my Rails app, I have a view that allows user to modify the
Imagine in rails I have @template that is an instance of ActionTemplate::View . Question
I have a Rails app displaying the workshifts of employees in a table. The
I have limited screen space for a table that I'm displaying, so I'm showing
I have an XML view in a rails app, and need to insert in
I'm making a simple search form in rails. In my search view I have

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.