【发布时间】:2015-05-03 17:36:41
【问题描述】:
已经创建了一个复选框 - 简单形式的布尔函数,想知道控制器如何在索引指示时隐藏帖子。 当用户创建帖子时,他可以选择从所有帖子列表 (index.html.haml) 中隐藏该帖子。在表单中我创建了活动布尔输入,因此如果活动为真,则帖子会显示在索引中,如果活动为假,则帖子将从索引中隐藏。
= 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
【问题讨论】:
-
请详细说明你想做什么。
-
@Marwen 当用户创建帖子时,他可以选择从所有帖子列表 (index.html.haml) 中隐藏该帖子。在我创建了活动布尔输入的表单中,如果活动为真,则帖子会显示在索引中,如果活动为假,则帖子将从索引中隐藏。
标签: ruby-on-rails ruby-on-rails-4 checkbox haml simple-form