I've been learning Rails for a while now and have finally gotten this Pinterest-style application up and running.
What's left for me to do now is create user profiles. I want it to be so that when you visit a user profile, we can see all of the things that particular user uploaded. The problem, however, is that I don't know where to begin. Is there a gem for this sort of task? How do I route each unique username to a different path (eg. abc.com/username)?
By the way -- I have used Devise for authentication
These are the steps I did to create that kind of environment: Run these commands on the command line:
rails new pinterest
rails generate scaffold user name:string age:integer
rake db:create
rake db:migrate
Make the route:
# routes.rb
get '/:name' => "users#show"
Update the set_user method to find the user by name
# users_controller.rb
def set_user
@user = User.find_by_name(params[:name])
end
Then all you need to do is create a new user and access it using it's name.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.