Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 显示用户';s轨道上的立柱不工作_Ruby On Rails - Fatal编程技术网

Ruby on rails 显示用户';s轨道上的立柱不工作

Ruby on rails 显示用户';s轨道上的立柱不工作,ruby-on-rails,Ruby On Rails,我得到nil:NilClass错误的未定义方法“posts: 主计长员额: 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) %> 通过在路由中设

我得到nil:NilClass错误的未定义方法“posts:
主计长员额:

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) %>

通过在路由中设置用户名将其传递给参数

<%= link_to post.user.username, liked_posts_path(username: post.user.username) %>

通过在路由中设置用户名将其传递给参数

<%= link_to post.user.username, liked_posts_path(username: post.user.username) %>


@user=user。通过用户名(params[:username])查找。\u
因此返回nil。因此您没有具有该用户名的用户,或者您没有将该用户名作为参数传递。
@user=user.find by_username(params[:username])
,因此返回nil。因此您没有具有该用户名的用户,或者您没有将该用户名作为参数传递。