使用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.
http://api.rubyonrails.org/classes/ActionController/Resources.html
上一篇:Rails 3的顺序按指望的has_many:通过顺序、Rails、has_many
下一篇:有没有的ActiveRecord的模式在Java中像Ruby中一个一个实现?有的、模式、Ruby、ActiveRecord