0

まず、参照するテーブルのスキーマは次のとおりです

create_table "microposts", :force => true do |t|
    t.text     "content"
    t.integer  "user_id"
    t.datetime "created_at",                         :null => false
    t.boolean  "review",          :default => false

管理者がレビュー = true のすべての投稿を表示できるビューを作成し、管理者が個々の投稿を承認または削除できるようにしたいと考えています。

更新 これをユーザーコントローラーに追加しました

class UserController < ApplicationController
def review
    @microposts = Micropost.where(review: true)
  end

これが私がこれまでに持っているreview.html.erbです

   <% provide(:title, 'Review Shares') %>

<% if signed_in? && if current_user.admin? %>
<% @microposts.each do |mpost| %>
    <%= link_to "delete", "/micropost/#{mpost.id}", method: :delete,
                                 confirm: "You sure?",
                                 title: mpost.content %>
  <% end %>
<% end %>
  <% end %>

「レビュー」の値をfalseに変更するオプションを使用して、実際に投稿を表示するにはどうすればよいですか?

4

2 に答える 2

0

スコープを作成できます

scope :reviewed, where(:review => true)

Model.reviewedreview が true であるすべてのレコードを返します。

@reviewed_microposts = Micropost.reviewed (assuming the model name is Micropost)

このインスタンス変数は、ビューで反復して表示できます。

于 2013-04-06T21:35:48.910 に答える