Skip to content

Instantly share code, notes, and snippets.

@negabaro
Created October 17, 2017 20:52
Show Gist options
  • Save negabaro/b02bbcd23e444715f6cf7e800561a92a to your computer and use it in GitHub Desktop.
Save negabaro/b02bbcd23e444715f6cf7e800561a92a to your computer and use it in GitHub Desktop.
Rails AASM controller example
def create
@article = current_user.articles.build(article_params)
if @article.valid?
@article.save!
case params[:ope][:cmd]
when 'publish'
@article.publish!
puts "hi this is publish zone"
flash[:success] = '記事を公開しました。'
when 'save'
#@article.draft!
puts "hi this is draft zone"
flash[:success] = '記事を保存しました。'
else
raise
end
redirect_to @article
else
redirect_to :new
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment