Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top