Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Ruby

Ruby On Rails

2 Answers

Maciej Czuchnowski
Maciej Czuchnowski
36,440 Points

You don't have any section for name of the authors in your index.html.erb file, so they won't show up :). You only have content, date and links for edit/delete in your markup.

So how would I fix this?

<%= link_to status.name %> ? In the index.html.ERB file?

Seriously... :/

Okay let me take a screenshot.

This is the instructors POV.

http://gyazo.com/66f298e063cbc1731118897bf3923aba

Now here is my POV.

http://gyazo.com/f03544a6f610fa36fbdec53c3514b98e

See I am missing the name part.

Maciej Czuchnowski
Maciej Czuchnowski
36,440 Points

Yes, you don't have any name section in your index.erb. You can do it like this:

<div class="page-header">

  <h1> All Statuses </h1>

</div>

<%= link_to "Post A Status", new_status_path, class: "btn btn-success" %>

<% @statuses.each do |status| %>

  <div class="status">
  <p>
    <strong>Name</strong>
  </p>
    <p>
      <%= status.content %> 
    </p>

      <div class="meta">
        <%= link_to time_ago_in_words(status.created_at) + " ago", status %>
          <span class="admin">
            | <%= link_to "Edit", edit_status_path(status) %>
            | <%= link_to "Delete", status, method: :delete, data: { confirm: "Are you sure you want to delete this status?" } %>
          </span>
      </div>
  </div>
<% end %>

You would have this section if you followed the video I mentioned.

THANK YOU SO MUCH!! :)

Maciej Czuchnowski
Maciej Czuchnowski
36,440 Points

Dominick,

There are tons of reasons why your code might not be doing what you want it to do. Please do the following whenever posting your questions on the forum:

  • Make a proper title for the question - "Ruby on Rails" is too vague and doesn't tell us much - be more specific in the title

  • Include your code - ideally you would have your whole project on GitHub or BitBucket to link here and let us see what might be wrong; if it's something simpler, you can paste code from some of your files that are related to the problem (controller and view in most cases)

  • Instead of linking the video or challenge in the body of the question, you can go to that link and click "Ask a Question" button. This will automatically bind the question to this video or challenge, which in turn make sit easier to see what the question relates to in the list of forum posts.

I don't know how to use Git Hub and I don't really want to make an account. Second, I can get post the code. What files would I need to post?

Maciej Czuchnowski
Maciej Czuchnowski
36,440 Points

I think status_controller.rb and views/statuses/index.html.erb should be enough for now.

You should learn Git as soon as possible (http://teamtreehouse.com/library/git-basics) and read about GitHub. At some point you will be required to know how to use version control, no matter what language or framework you end up working with. Trust me on this.

Maciej Czuchnowski
Maciej Czuchnowski
36,440 Points

Also, as a sidenote, this course is very, very old and if you're using the newest Rails and newest versions of most of the gems use din these videos, the app won't work.

Yes I am aware this is an old tutorial. I have some gems installed that will counter act the new updates effecting it.

Here is my status.RB file.

class Status < ActiveRecord::Base
    attr_accessible :content, :user_id
    belongs_to :user
end

Then, here is my index.html.ERB file.

<div class="page-header">

  <h1> All Statuses </h1>

</div>

<%= link_to "Post A Status", new_status_path, class: "btn btn-success" %>

<% @statuses.each do |status| %>

  <div class="status">

    <p>
      <%= status.content %> 
    </p>

      <div class="meta">

        <%= link_to time_ago_in_words(status.created_at) + " ago", status %>

          <span class="admin">

            | <%= link_to "Edit", edit_status_path(status) %>

            | <%= link_to "Delete", status, method: :delete, data: { confirm: "Are you sure you want to delete this status?" } %>

          </span>

      </div>

  </div>

<% end %>

Also, I guess I will check the course out once I am done with this course.

Maciej Czuchnowski
Maciej Czuchnowski
36,440 Points

You posted a model, not the controller. I need app/controllers/statuses_controller.rb

My bad. I would like to thank you for helping me.

class StatusesController < ApplicationController
  before_action :set_status, only: [:show, :edit, :update, :destroy]

  # GET /statuses
  # GET /statuses.json
  def index
    @statuses = Status.all
  end

  # GET /statuses/1
  # GET /statuses/1.json
  def show
  end

  # GET /statuses/new
  def new
    @status = Status.new
  end

  # GET /statuses/1/edit
  def edit
  end

  # POST /statuses
  # POST /statuses.json
  def create
    @status = Status.new(status_params)

    respond_to do |format|
      if @status.save
        format.html { redirect_to @status, notice: 'Status was successfully created.' }
        format.json { render :show, status: :created, location: @status }
      else
        format.html { render :new }
        format.json { render json: @status.errors, status: :unprocessable_entity }
      end
    end
  end

  # PATCH/PUT /statuses/1
  # PATCH/PUT /statuses/1.json
  def update
    respond_to do |format|
      if @status.update(status_params)
        format.html { redirect_to @status, notice: 'Status was successfully updated.' }
        format.json { render :show, status: :ok, location: @status }
      else
        format.html { render :edit }
        format.json { render json: @status.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /statuses/1
  # DELETE /statuses/1.json
  def destroy
    @status.destroy
    respond_to do |format|
      format.html { redirect_to statuses_url, notice: 'Status was successfully destroyed.' }
      format.json { head :no_content }
    end
  end

  private
    # Use callbacks to share common setup or constraints between actions.
    def set_status
      @status = Status.find(params[:id])
    end

    # Never trust parameters from the scary internet, only allow the white list through.
    def status_params
      params.require(:status).permit(:name, :content)
    end
end
Maciej Czuchnowski
Maciej Czuchnowski
36,440 Points

OK, so as I mentioned in another answer, you get exactly what you type in your index.html.erb template - there is nothing about the authors and their names there.