简体   繁体   English

Rails Microposts显示全部

[英]Rails Microposts Show all

so, following M. Hartl's Tutorial, I have this static_pages controller that displays this 所以,按照M. Hartl的教程,我有这个static_pages控制器来显示它

class StaticPagesController < ApplicationController
def home
if signed_in?
  @micropost = current_user.microposts.build
  @feed_items = current_user.feed.paginate(page: params[:page])
end
end

def help
end

def about
end

def contact
end
end

And this makes it show on the home page, all of the current users' microposts, but only the current users 这使得它在主页上显示所有当前用户的微博,但仅显示当前用户

how do i make it show ALL Users micropost, every single one created? 我如何让它显示所有用户微博,每一个创建?

You are scoping the query to fetch only the current_user microposts. 您正在查询查询以仅获取current_user微博。 Micropost.all should get you all microposts. Micropost.all应该为您提供所有微博。 Also ensure that you havent already set some default scopes in your model, in which case you will have to use Micropost.unscoped . 还要确保您尚未在模型中设置一些默认范围,在这种情况下,您必须使用Micropost.unscoped

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM