M
M
mlwrm2016-03-29 18:06:55
Ruby on Rails
mlwrm, 2016-03-29 18:06:55

How to add _path to own url?

Added controller to routes.rb :
get 'userposts/:id', to: 'posts#userposts'

def userposts
    @user = User.find(params[:id])
    @posts = Post.where(user_id: @user.id).order('created_at DESC')
 end

but rake routes only outputs
GET /userposts/:id(.:format) posts#userposts

so there is no way to do the following
<%= link_to "my posts", userposts_path(current_user.id) %>

Because there is no 'userposts_path' method
How to fix it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey R, 2016-03-29
@malworm

Try

get 'userposts/:id', to: 'posts#userposts', as: :userposts

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question