title: Rails select query displaying all columns with odd formatting in view
body: <p>I'm new to Rails and I've hit my first wall. Up until now I've been able to use Google for the answer. To be honest, I think part of the problem is that I'm unable to properly explain the problem.</p>
  
  <p>My Rails Select query in the show.html.erb file is (1) displaying duplicate records and (2) displaying the data with odd formatting instead of plain text. I'll paste all code below to fully illustrate.</p>
  
  <p>I have a User model that has_many :works   </p>
  
  <pre><code>class User &lt; ActiveRecord::Base
    # Include default devise modules. Others available are:
    # :token_authenticatable, :confirmable,
    # :lockable, :timeoutable and :omniauthable
    devise :database_authenticatable, :registerable,
           :recoverable, :rememberable, :trackable, :validatable
  
    # Setup accessible (or protected) attributes for your model
    attr_accessible :email, :password, :password_confirmation, :remember_me, :first_name, :last_name, :works_attributes
    # attr_accessible :title, :body
  
    validates_presence_of :first_name, :last_name
    validates_uniqueness_of :first_name, :last_name, :email, :case_sensitive =&gt; false
  
    has_many :works
    accepts_nested_attributes_for :works
  </code></pre>
  
  <p>Here is my work model, which belongs_to user</p>
  
  <pre><code>class Work &lt; ActiveRecord::Base
    attr_accessible :description, :work_name, :users_id
  
    belongs_to :user
  end
  </code></pre>
  
  <p>And here is the users controller:</p>
  
  <pre><code>class UsersController &lt; ApplicationController
    def index
      @users = User.all
  
  respond_to do |format|
    format.html # index.html.erb
    format.xml  { render :xml =&gt; @users }
  end
  
  
  end
    def show
      @user = User.find(params[:id])
      @works = @user.works.all
      respond_to do |format|
        format.html # show.html.erb
        format.xml  { render :xml =&gt; @user }
      end
    end
  end
  </code></pre>
  
  <p>In my users show.html.erb view, I want to loop through the works that belong to a particular user. I setup the foreign key relationship with a user_id field to follow Rails convention. When the loop finds a work that belongs to the user, I want to display the work_name field.</p>
  
  <pre><code>&lt;% if @user.works.any? %&gt;
                      &lt;% @user.works.each do |user| %&gt;
                     &lt;%= @user.works(:select =&gt; 'work_name') %&gt;
                    &lt;% end %&gt;
                  &lt;% end %&gt;
  </code></pre>
  
  <p>However, this is the output I'm seeing on the website when viewing /users/1/:</p>
  
  <pre><code>[#&lt;Work id: 1, work_name: "WorkTest1", description: "I am the co-founder and CEO of WorkTest1, a website t...", created_at: "2013-02-12 00:33:19", updated_at: "2013-02-12 00:33:19", user_id: 1&gt;, #&lt;Work id: 2, work_name: "WorkTest2", description: "test", created_at: "2013-02-12 00:33:19", updated_at: "2013-02-12 00:33:19", user_id: 1&gt;] [#&lt;Work id: 1, work_name: "WorkTest1", description: "I am the co-founder and CEO of WorkTest1, a website t...", created_at: "2013-02-12 00:33:19", updated_at: "2013-02-12 00:33:19", user_id: 1&gt;, #&lt;Work id: 2, work_name: "WorkTest2", description: "test", created_at: "2013-02-12 00:33:19", updated_at: "2013-02-12 00:33:19", user_id: 1&gt;]
  </code></pre>