Ruby on rails 在视图中显示表列中的数据

Ruby on rails 在视图中显示表列中的数据,ruby-on-rails,Ruby On Rails,我能够为提交数据的用户显示表中的信息。我似乎无法设置如何显示表中的所有用户信息 index.html.erb: #This gives undefined local variable or method 'bio'. bio.content works on the user page if signed in and shows data from the user only. <%= bio.content.all %> user_controller.rb:

我能够为提交数据的用户显示表中的信息。我似乎无法设置如何显示表中的所有用户信息

index.html.erb:

#This gives undefined local variable or method 'bio'. bio.content works on the user page if signed in and shows data from the user only.

<%= bio.content.all %>
user_controller.rb:

            def show
            @bio= User.all
        end
  def show
    @bio = current_user.bio.build

有人能帮我显示我到底缺少什么,这样我就可以显示数据库中的所有bio信息,而不是只允许显示登录用户的个人资料中的数据。

您需要查看
@bio.content.all
。您可能想用一些HTML来构造它:

if @bio
   @bio.content.all.each do |b|
      <!-- some HTML to show the `b` record -->
   end
end
if@bio
@bio.content.all.each do|b|
结束
结束

为nil提供未定义的方法“content”。Content是我的数据库表名,我必须在def show下的bio controller中定义它吗?今天早上我尝试了几条不同的路线。问题可能在我的路线上。将对其进行一些调整,看看是否能找到解决方案。@xps15z您的帖子表明您设置了
@bio
。如果可能的话,它是空的,那么你可以检查一下nil。如果有其他的“业务逻辑”在它是否为空的时候出现,您需要揭示它以获得更详细的答案。现在,您只有几段代码显示。:)