我得到了未定义的方法`帖子'为零:NilClass错误:
帖子控制器:
def liked
@user = User.find_by_username(params[:username])
@posts = @user.posts
render action: :index
end
Index.html.erb:
<%= link_to post.user.username, liked_posts_path(post.user.username) %>
答案 0 :(得分:2)
通过在路径
中设置将用户名传递给params<%= link_to post.user.username, liked_posts_path(username: post.user.username) %>