ruby on rails - how to make a post require a manual approval by admin before getting displayed? -
i new rails developer , have rails app allow users make post while allowing them option check checkbox. want able manually review posts checked users during posting process. right getting posted want review process in place checkmarked posts. simplest , easiest way put review in place?
here's post controller right now
def create @post = current_user.posts.build(params[:post]) if @post.save flash[:success] = "shared!" redirect_to root_path else @feed_items = [] render 'static_pages/home' end end
for this, better keep data-type of "reviewed" field "boolean" (in migration files).
for putting check box in view, check: http://guides.rubyonrails.org/form_helpers.html#helpers-for-generating-form-elements
also, note if want validate presence of boolean field (where real values true , false), can't use:
validate :field_name, :presence => true
this due way object#blank? handles boolean values. false.blank? # => true in case, can use:
validates :field_name, :allow_nil => true, :inclusion => {:in => [true, false]}
you can omit ":allow_nil => true", above validation statement if assigning false default value newly created posts (and require before validations triggered).
Comments
Post a Comment