セッションを含むより良い方法があるかもしれません。2 番目の形式と多くの JavaScript を使用して、セッション ハッシュを完全に使用することは避けたいと思います。
これが私がそれを処理する方法です。最初のフォームはまったく変更されず、review という新しいアクションに送信されるだけです。
レビュー アクションは、レビュー用の変更を表示し、編集リンクと確認ボタンを表示します。また、レビュー アクションに再度送信される非表示の要素で、前のページからフォームを再作成します。
確認ボタンは更新アクションに送信されます。
編集リンクをクリックすると、レビュー領域が非表示になり、前のページからの複製が表示されます。
ポイントを突き詰めるためのサンプルコードを次に示します。
アプリ/コントローラー/example_controller.rb
class ExampleController < ApplicationController
def edit
@example = Example.find(params[:id])
end
def review
@example = Example.find(params[:id])
@example.update_attributes(params[:example])
@example.valid?
end
def update
@example = Example.find(params[:id])
@example.update_attributes(params[:example])
if @example.save
redirect_to @example
else
render :action => :review
end
end
end
アプリ/ビュー/例/_form.html.erb:
<% form_form @example, :url => {:action => "review"} do |f|%>
...
Form inputs go here
...
<% end %>
アプリ/ビュー/例/edit.html.erb:
<%= render :parital => form %>
app/views/examples/review.html.erb:
<div id="review">
...
content for review goes here
...
<%= link_to_function "Edit", "$('review').hide(); $('edit').show()"
<% form_for @example do |f| %>
<%= hidden_field :attribute, @example.attribute %>
...
hidden_field for each attribute
...
<%= submit_tag "Accept These Changes" %>
<% end %>
</div>
<div id="edit" style="display:none">
<%= render :partial => 'form' %>
</div>