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

Drew Konopasek
Drew Konopasek
5,055 Points

Link to 'My Profile' page

Hey everyone I am trying to add a link to my ruby application that will go to a current user's profile page that is logged in

<li> <%= link_to "My Profile", profiles_show_path %> </li>

<% if logged_in? %>

When i type rake routes profiles_show is what comes up as the command. However when I add this code I keep getting a page does not exist alert. What do I need to add to this code in order for a current user to be able to look at his or her profile by clicking on the link? Thank you so much!

4 Answers

Maciej Czuchnowski
Maciej Czuchnowski
36,440 Points

You have to pass something as an argument to the profiles_show_path. If you're using Devise, maybe profiles_show_path(current_user) will work, although I never tried that. Also, it depends how your controller looks like.

Drew Konopasek
Drew Konopasek
5,055 Points

Prefix Verb URI Pattern Controller#Action

profiles_show GET /profiles/show(.:format) profiles#show

login GET /login(.:format) user_sessions#new

logout DELETE /logout(.:format) user_sessions#destroy

users GET /users(.:format) users#index

POST /users(.:format) users#create

new_user GET /users/new(.:format) users#new

edit_user GET /users/:id/edit(.:format) users#edit

user GET /users/:id(.:format) users#show

PATCH /users/:id(.:format) users#update

PUT /users/:id(.:format) users#update

DELETE /users/:id(.:format) users#destroy

username_index GET /username(.:format) username#index

POST /username(.:format) username#create

new_username GET /username/new(.:format) username#new

edit_username GET /username/:id/edit(.:format) username#edit

username GET /username/:id(.:format) username#show

PATCH /username/:id(.:format) username#update

PUT /username/:id(.:format) username#update

DELETE /username/:id(.:format) username#destroy

user_sessions POST /user_sessions(.:format) user_sessions#create

new_user_session GET /user_sessions/new(.:format) user_sessions#new

password_resets POST /password_resets(.:format) password_resets#create

new_password_reset GET /password_resets/new(.:format) password_resets#new

edit_password_reset GET /password_resets/:id/edit(.:format) password_resets#edit

password_reset PATCH /password_resets/:id(.:format) password_resets#update

PUT /password_resets/:id(.:format) password_resets#update

views GET /views(.:format) views#index

POST /views(.:format) views#create

new_view GET /views/new(.:format) views#new

edit_view GET /views/:id/edit(.:format) views#edit

view GET /views/:id(.:format) views#show

PATCH /views/:id(.:format) views#update

PUT /views/:id(.:format) views#update

DELETE /views/:id(.:format) views#destroy

root GET / views#index

terms GET /terms(.:format) static_pages#terms

GET /:id(.:format) profiles#show

Drew Konopasek
Drew Konopasek
5,055 Points

Class ProfilesController < ApplicationController

def show

@user = User.find_by_username(params[:id])

if @user
    @views = @user.views.all
    render action: :show
else

    render file: 'public/404', status: 404, formats: [:html]

end end end

Drew Konopasek
Drew Konopasek
5,055 Points

Hi Maciej I am using Bcrypt for the user system. I have tried (current_user) before and it takes me to a 404 page. I have also tried user_path(current_user), but that takes me to a page that shows all the users settings not his or her actual profile page.