I want to allow the admin to review the description. So, whenever user posts the description admin can either approve or reject it. If approved it'll display on the index page. At the moment the user can add the description but it can't be reviewed by admin. Is there any way I could do this?
index.html.erb
<% @posts.each do |post| %>
<p> <%= post.description %> </p>
<% end %>
admin/post.rb
ActiveAdmin.register Post do
permit_params :description
index do
id_column
column :description
end
form do |f|
f.inputs do
f.input :description
end
f.actions
end
end
add new boolean field to post called reviewed with default value false:
class AddReviewedToPosts < ActiveRecord::Migration
def self.up
add_column :posts, :reviewed, :boolean, default: false
end
def self.down
remove_column :posts, :reviewed
end
end
then create on AA under index page a button the set it as reviewed:
index do
id_column
column :description
column "" do |post|
link_to 'Mark as reviewed', admin_posts_reviewed_path(post)
end
end
then the last thing create a reviewed action on admin/posts.rb
:
def reviewed
@post = Post.find(params[:id])
if @post.present?
@post.update_attribute(:reviewed, true)
flash[:notice] = 'Post marked as reviewed'
else
flash[:error] = 'Could not find post'
end
redirect_to admin_posts_path
end
don't forget to add the action to routes.rb!
now you can display it if the boolean field is true.
code is not tested this is from my head.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.