Ruby On Rails - "undefined method` id 'for 4: Fixnum"

I recently decided to list everything usersin my Ruby On Rails application, since I could not figure out how to list them in any other way, I decided to use partial ones. My administration page has the following: just connected to my own admin controller:

<%= render :partial => User.find(:all) %>

Then I have a file with a name _user.html.erbin the view folder of my users. It contains the following:

<ul>
<% div_for @user.object_id do %>
    <li><%= link_to user.username, user.username %></li>
<% end %>
</ul>

When the application starts and I go to the administration page, I get the following error:

undefined id method for 4: Fixnum

He talks about this because of this line (which is in the partial file):

<% div_for @user.object_id do %>

, ( , ). , @user, .

+5
4

, div_for , id. fixnum ( @user.object_id), id.

, @user @user.object_id, .

user @user, rails 3 .

+8

.object_id. , object_id! ? div_for div , .object_id!

0

instead of the object, you use it in the varsa column or visa that you use at that time, you will get such an error.

Example

I use id instead of user = User.first object.

0
source

Try it, it worked for me.

@item.unit_of_measure.name 

instead

@item.unit_of_measure_id.name
0
source

All Articles