Rails 4:Simple-活动和非活动的表单复选框post

Rails 4:Simple-form checkbox for active and inactive post

创建了一个简单形式的复选框 - 布尔函数,想知道控制器如何在索引指示时隐藏 post。 当用户创建 post 时,他可以选择从所有 post 列表 (index.html.haml) 中隐藏 post。在我创建了 active 布尔输入的表单中,如果 active 为真 post 则显示在索引中,如果 active 为假则 post 从索引中隐藏。

= simple_form_for @post do |f|
 = f.input :post
 = f.input :active ,:input_html => { :checked => true }
 = f.submit

index.html.haml

- @posts.each do |post|
 %h2.post= link_to post.post, post



class PostsController < ApplicationController
 before_action :find_post, only: [:show, :edit, :update, :destroy]
 before_action :authenticate_user!,except:[:index,:show]

 def index
  @posts = Post.all.order("created_at DESC")
  @post = Post.new

 end

如果我得到你想要做的,那就是隐藏 index action

上的非活动帖子
def index
  @posts = Post.where(active: true).order("created_at DESC")
  @post = Post.new
end