Reputation: 69
How to do that posts will publish only after admin appriving in Ruby on Rails app using (State_machine or Workflow)?
Upvotes: 0
Views: 202
Reputation: 3568
I wouldn't bother with state_machine
or workflow
gems, since you have very few states and behaviours tied to them.
Those gems are more for running code based of very many states.
Just take a look at the Vehicle
example in the state_mahcine
docs.
https://github.com/pluginaweek/state_machine#example
I've achieved what you're trying to do before by simply using an enum
.
Add an enum
to your model called status
.
enum status: [:draft, :review, :published]
You will need to add an integer
column called status
to your postings.
add_column :posts, :status, :integer, default: 0, null: false
Now wherever you are showing the posts simply query out the unpublished posts.
@posts = Post.published
I added the statuses :draft
, :review
and :published
, but you could have as few or many enums.
Upvotes: 1