문제

I've been creating blogs using various RoR tutorials I've found around the internet (right now I'm working on the one found on Udemy, though I'm sure they're all similar), and currently I'm working on a blog with RailsAdmin where users can submit posts and the admin has the ability to review and delete them.

However, I'm trying to set it up so that posts can be submitted, but cannot be viewed on the page until the admin approves them, and I've been through several app creations but I can't figure out how this works. I apologize if this is a total newbie question but it's driving me nuts.

도움이 되었습니까?

해결책

I would suggest only displaying the posts that have a "published" field (make this a boolean called :published. on the admin side, have it run so that only the admin can see that field and if they check the check box, the post is then "published" and viewable by everyone.

in terminal

rails g migration add_published_to_posts

in your migration file

class AddPublishedToPosts < ActiveRecord::Migration
  def change
    add_column :posts, :published, :boolean
  end
end

in terminal

rake db:migrate

then in your posts index method (in the posts controller)

@posts = Post.where(:published => true)

I'm not going to write out the form for you, but you get the idea...

I would also investigate Devise as gem for setting up authorization for the admin.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top