Alex Cowley
Alex Cowley

Reputation: 123

Why is result returning hex instead of actual value?

I am following Michael Hartl's ROR Tutorial and for some reason my Users are getting returned in the browser as hex instead of their name. Why is this?

class UsersController < ApplicationController

def index
@users = User.all
end

def new
end


end


class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :confirmable,
# :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
     :recoverable, :rememberable, :trackable, :validatable
# attr_accessible :title, :body

has_many :relationships, :foreign_key => "follower_id", :dependent => :destroy
has_many :followed_users, :through => :relationships, :source => :followed
has_many :reverse_relationships, foreign_key: "followed_id", class_name:     "Relationship", :dependent => :destroy

has_many :followers, :through => :reverse_relationships, :source => :follower

def following?(other_user)
relationships.find_by(followed_id: other_user.id)
end

def follow!(other_user)
relationships.create!(followed_id: other_user.id)
end

def unfollow!(other_user)
relationships.find_by(followed_id: other_user.id).destroy!
end


end

<h1>All Users</h1>

<ul class="users">
<% @users.each do |user| %>
<li>
    <%= link_to user, user %>
</li>
<% end %>
</ul>

<% provide(:title, @user) %>
<div class="row">
<aside class="span4">
    <section>
        <h1>
            <%= @user %>
        </h1>
    </section>
    <section>
    </section>
</aside>
<div class="span8">
    <%= render 'follow_form' if signed_in? %>
</div>
    </div>

Upvotes: 2

Views: 1079

Answers (1)

Rails Guy
Rails Guy

Reputation: 3866

Its not Hex, its returning an object.Try to print user.name or attribute or field you have in user table for user name. Try with :

<%= link_to user.name, user %>

instead of

<%= link_to user, user %>

and

<%= @user.name %>

instead of

<%= @user %>

All Users

<ul class="users">
<% @users.each do |user| %>
<li>
    <%= link_to user.name, user %>
</li>
<% end %>
</ul>

<% provide(:title, @user) %>
<div class="row">
<aside class="span4">
    <section>
        <h1>
            <%= @user.name %>
        </h1>
    </section>
    <section>
    </section>
</aside>

Upvotes: 3

Related Questions