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 trialEdward Lim
Courses Plus Student 753 PointsHow to find a devise user by user_id?
So as im following along in this tutorial. I have made some changes because I have already taken a course prior to this and I wanted to challenge myself.However, I have come to a problem that has me scratching my head.
What I would like to do is get the user_id
of a user's show
page. What the tutorial has done is create a new field for devise
, profile_name
. (I understand the importance of this because we would not want duplicate routes for two different users)
I skipped this step, because i did not want my users to be identified that way. I wanted them to be identified by their user_id/
+ first_name
+ last_name
. In doing what the tutorial did, what he achieved was that he created custom routes for each individual user signed up to his site by the use of their unique profile_name
. In my case it would be user_id/
+ first_name
+ last_name
. If someone could shed some light on this and hopefully also point me to a resource I could potentially learn more on this subject I would really appreciate it. What really appealed to me was the fact that you were able to create custom routes for each individual on your site. I did think of using
@user = User.find(current_user) but that didnt work so well. It shows on the page but did not create custom routes like i thought it would. For instance in my case it would be http://localhost:3000/105/edwardlim.
Thanks for reading and have a nice day! :D
This is what you guys had in the tutorial.
class ProfileController < ApplicationController
before_filter :authenticate_user!, only: [:show]
def show
@user = User.find_by_profile_name(params[:id])
//@user = User.find_by_user_id(params[:id]) //my code that I thought would work
if @user
@statuses = @user.statuses.all
render action: :show
else
render file: 'public/404', status: 404, formats: [:html]
end
end
end
ROUTES FILE
Rails.application.routes.draw do
get '/:id', to: 'profile#show'