When I go to an index view for my Rails program, it is suppose to iterate over all the object's properties and display each one in turn. My program is doing this perfectly as expected.
It is ALSO then displaying an array of each instance below the normal list. I am not sure why. Any thoughts?
In the controller:
def index
@user = User.find(params[:user_id])
@characters = @user.characters.all
end
In the View
<%= @characters.each do |char| %>
<%= char.name %>
<% end %>
What is displayed on screen from the above:
Joe Jane [#<Character id: 1, allies: "none", enemies: "none", description: "something", user_id: 6, race_id: 1, created_at: "2019-08-11 08:37:08", updated_at: "2019-08-11 08:37:08", name: "Joe">, #<Character id: 2, allies: "none", enemies: "none", description: "something", user_id: 6, race_id: 1, created_at: "2019-08-11 08:39:49", updated_at: "2019-08-11 08:39:49", name: "Jane">]
I expect the index page for a user's characters to only display
JoeJane
Currently it actually displays:
Joe Jane [#Character id: 1, allies: "none", enemies: "none", description: "something", user_id: 6, race_id: 1, created_at: "2019-08-11 08:37:08", updated_at: "2019-08-11 08:37:08", name: "Joe">, #Character id: 2, allies: "none", enemies: "none", description: "something", user_id: 6, race_id: 1, created_at: "2019-08-11 08:39:49", updated_at: "2019-08-11 08:39:49", name: "Jane">]
The program seems to be with me running the loop at all. I have taken out the char.name part and just run an empty block and get the same result as above minus the Joe Jane bit. I have reset my server, dropped and reloaded by database, and compared it to similar code I have on other projects that do not produce these odd results. I am not sure what is causing this oddity.