Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby

Profile page not showing the content !!

Im creating a Treebook clone using rails but i am stuck with the profile page not showing the Statuses and the content. This is the Code file:

Apps/Controller/profiles_controller.rb

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 Apps/views/profiles/show.html.erb

<%if @statuses%>

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

<% end %> <% end %>

my github: https://github.com/Ahmedalthani/Skillbook/commits/master

3 Answers

This might be the problem.

class ProfilesController < ApplicationController
   def show
        # You're passing in the ID instead of the profile name when searching for a User.
    @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

Thanks for you helps. Do you mean passing the profile_name as a params ?. i tried that but i am still getting an error.

         ```ruby
            class ProfilesController < ApplicationController
       def show
    # You're passing in the ID instead of the profile name when searching for a User.
    @user = User.find_by_profile_name(params[:profile_name])
     if @user
    @statuses = @user.statuses.all
    render action: :show
   else
      render file: 'public/404' , status: 404 , formats: [:html]
  end
    end
end
        ```

Ahmed,

I looked into your repo. It looks like there are a few things that need to be fixed. It might be better to go through the entire Rails course to build a stronger base before moving on to create a project.

As for the current problem, we need to change a few things like including:

  1. The routes for the profiles needs to be defined so that either the ID or the profile name is used as part of the url.
  2. You need strong parameters to whitelist attributes to use within your controller. Check out this link for more info about strong params: http://edgeguides.rubyonrails.org/action_controller_overview.html.