我一直在尝试为我的rails应用程序创建一个订单确认页面,我不太确定如何以一种宁静的方式去做.
在this问题上有一些答案让我在那里中途,但问题是我不太确定如何在rails视图中设置表单,以便它将用户带到包含所有详细信息的确认页面而不是创建动作.
现在我的观点很简单:
<% form_for :order do |f| %> <%= f.error_messages %> <p> <%= f.label :first_name %><br /> <%= f.text_field :first_name,:size => 15 %> </p> <p> <%= f.label :last_name %><br /> <%= f.text_field :last_name,:size => 15 %> </p> (Be sure to enter your name as it appears on your card) <p> <%= f.label :card_type %><br /> <%= f.select :card_type,[["Visa","visa"],["MasterCard","master"],["Discover","discover"],["American Express","american_express"]] %> </p> <p> <%= f.label :card_number %><br /> <%= f.text_field :card_number %> </p> <p> <%= f.label :card_verification,"Card Verification Value (CVV)" %><br /> <%= f.text_field :card_verification,:size => 3 %> </p> <p> <%= f.label :card_expires_on %><br /> <%= f.date_select :card_expires_on,:discard_day => true,:start_year => Date.today.year,:end_year => (Date.today.year+10),:add_month_numbers => true %> </p> <p><%= f.submit "Submit" %></p>
我应该做些什么来引导用户进入显示所有订单详细信息的确认页面?
谢谢!
贤治
解决方法
There were a few answers on this
question that got me halfway there,
but the problem was that I wasn’t
quite sure how to set up the form in
the rails view so that it would take
the user to a confirmation page with
all their details instead of a create
action.
将表单定向到非标准页面非常简单.
添加网址选项form_for.
这样
<% form_for :order do |f| %>
变
<% form_for :order :url => {:action => "confirm"} do |f| %>
您需要在路线中创建确认操作,但这只涉及到:
map.resources :orders,:collection => {:confirm => :get}
您现在需要的只是基本的控制器操作和视图:
def confirm @order = Order.new(params[:order]) unless @order.valid? render :action => :new else end end
您的视图应该与show视图几乎完全相同,并添加了一个将表单提交给create动作的表单.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。