ruby - Getting param from friendly url like http://localhost:3000/user/adem-balka with Rails 5 -


so want display posts user in his/her profile page @ top user details, below posts.

i know can param url http://localhost:3000/posts?category=article

with

if params[:category]   @category_id = category.find_by(title: params[:category]).id   @posts = post.where(category_id: @category_id) end 

but param doesn't work when have url http://localhost:3000/user/adem-balka

so, how can user name find id , pull posts user id?

thank all.

the name of parameter in url set in routes file.

if @ routes in config/routes.rb, should able find line(s) corresponds user model. should this:

get '/users/:name', to: 'users#show'

this means if go /users/adem-balka, params[:name] set 'adem-balka'. can access parameter in corresponding controller function.


Comments

Popular posts from this blog

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -

minify - Minimizing css files -