Ruby on Rails的:确认页面的ActiveRecord对象创建 [英] Ruby on Rails: Confirmation Page for ActiveRecord Object Creation
问题描述
使用Ruby on Rails的我想创建一个ActiveRecord对象之前确认页面。用户将看到他们正在创建提交前和对象被保存在数据库中
Using Ruby on Rails I want a confirmation page before creating an ActiveRecord object. The user will see a preview of the item they are creating before submitting and the object being saved in the database
一个常见的模式;
A common pattern;
- 在用户访问/项/新
- 在用户输入的信息并点击提交
- 在用户被重定向到/项/确认它显示的条目,点击提交或编辑,纠正错误
- 在对象被保存
你将如何实现它?
推荐答案
我可能会增加一个preVIEW行动的routes.rb中文件的模型:
I would probably add a "preview" action to the routes.rb file for that model:
map.resource :objects, :new => { :preview => :post }
您将获得本 preVIEW
张贴的 preview_object_url
命名路由操作。您将需要以同样的方式你会在你的创建
操作,这样从根本上创建对象
:
You would get to this preview
action by POSTing the preview_object_url
named route. You would need to essentially create the Object
in the same way you would in your create
action, like this:
def preview
@object = Object.new(params[:object])
end
该网页将然后发布到创建
动作,然后将创建对象。这是pretty的直线前进。
This page would then POST to the create
action, which would then create the Object. It's pretty straight forward.
<一个href="http://api.rubyonrails.org/classes/ActionController/Resources.html">http://api.rubyonrails.org/classes/ActionController/Resources.html
这篇关于Ruby on Rails的:确认页面的ActiveRecord对象创建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!