No commit activity in last 3 years
No release in over 3 years
confirmatin view on model creation / changes
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 0.9.2.2
~> 3.11
>= 0

Runtime

 Project Readme

Activerecord::Confirmable

Railsで、controllerにconfirmアクションを作らずに、確認画面を実装するためのモジュールです。

Installation

Add this line to your application's Gemfile:

gem 'activerecord-confirmable'

And then execute:

$ bundle

Or install it yourself as:

$ gem install activerecord-confirmable

Usage

このモジュールをモデルにincludeすると、confirmedアトリビュートが追加されます。フォームに、hidden_field :confirmed を追加すると確認画面に遷移するようになります。#confirmation? がtrueの場合はモデルが確認画面の状態なので、適切にviewを切り替えてください。

                     validation fail
      +---------------+-----------------------------+
      |               |                             |
      v               |                             |
+--------------+    submit    +--------------+    submit
|  new / edit  |  ----------> | confirmation |  ---------->  done
+--------------+              +--------------+
confirmed != '1'              confirmed == '1'

      ^                                |
      |  back (set confirmed = false)  |
      +--------------------------------+

exapmle:

class Article
  include ActiveRecord::Confirmable
end

class ArticlesController
  def create
    @article = Article.new(params[:article])
    @article.confirmed = false if params[:commit] == "back"
    if @article.save
      redirect_to @article
    else
      render action: "new"
    end
  end

  def update
    @article = Article.find(params[:id])
    params[:article][:confirmed] = false if params[:commit] == "back"
    if @article.update_attributes(params[:article])
      redirect_to @article
    else
      render action: "edit"
    end
  end
end

articles/_form.html.erb
  <%= form_for(@article) do |f| %>
    <%= f.text_field :title %>
    <%= f.submit f.object.confirmation? ? "submit" : "confirm" %>
    <%= f.submit "back" if f.object.confirmation? %>
    <%= f.hidden_field :confirmed %>
  <% end %>

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request