I have to call Article.to_draft
/to_archive
/publish
method depending on the presence of the corresponding key in the params
hash.
I do, however, have no idea to implement it properly.
def update_state
method = if params[:draft].present?
:to_draft
elsif params[:archived].present?
:to_archive
else
:publish
end
@article.send method
end
The code works, but the number of possible states of an article will probably grow in the future.
I would like to have a hash like this:
{ draft: :to_draft, archived: :to_archive, default: :publish }
and let #update_state
decide what should be called, based on the params
hash.