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 Build a Simple Ruby on Rails Application Building the Profile Page Scoping

Kris Chery
Kris Chery
935 Points

Uninitialized constant written shows up when I have to go the profile page. Rails 4.2.4

I can't seem to accept that page by the user_id number or by the profile name

Profile controller

class ProfilesController < ApplicationController

  def show
    @user = User.find_by_profile_name(params[:id])
    if @user
      @statuses = @user.statuses.all
      render action: :show
    else
      render file: 'public/404', status: 404, formats: [:html]
    end
  end
end

show.html.erb

<div class="page-header">
  <h1><%= @user.full_name %></h1>
</div>

<% if @statuses %>
  <% @statuses.each do |status| %>
    <div class="well">
      <%= status.content %>
      <hr />
      <%= link_to time_ago_in_words(status.created_at), status_path(status) %> ago
    </div>
  <% end %>
<% end %>

User model page

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

    validates :first_name, presence: true
    validates :last_name, presence: true
    validates :profile_name, presence: true, uniqueness: true


    def full_name
     full_name = "#{first_name}  #{last_name}"
    end

end

Did you get this fixed?

Kris Chery
Kris Chery
935 Points

Not quite, I have run into some new issues with it. I have started working on my own app in hope that i figure where i went wrong.

OK - cool. If you want me to have a look at the Treebook code, just link me to the Github report and I'll take a look.

Steve.