ruby-on-rails - rails 中的订单确认页面

标签 ruby-on-rails forms rest routes confirmation

我一直在尝试为我的 rails 应用程序创建一个订单确认页面,但我不太确定如何以一种 Restful 方式进行。

关于 this 问题的一些答案让我半途而废,但问题是我不太确定如何在 rails View 中设置表单,以便将用户带到包含所有详细信息的确认页面而不是创建操作。

现在我的观点很简单:

        <% 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.



将表单定向到非标准页面非常简单。

添加一个 url 选项 form_for
这样的
<% form_for :order do |f| %>

变成
<% form_for :order :url => {:action => "confirm"} do |f| %>

您需要在 route 创建确认操作,但这仅涉及:
map.resources :orders, :collection => {:confirm => :get}

你现在需要的只是一个基本的 Controller Action 和一个 View :
def confirm
  @order = Order.new(params[:order])
  unless @order.valid?
    render :action => :new
  else       
  end
end

您的 View 应该与 show View 几乎相同,只是添加了一个表单,将 @order 提交给 create 操作。

关于ruby-on-rails - rails 中的订单确认页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1903349/

相关文章:

ruby-on-rails - 建立一个与之前位置不同的排名列表,比如排名 2 (+6)

php - 在文本文件中转换 "enter"in\n

html - 选择选项中的删除线文本

java - 使用 webtarget 从客户端调用剩余请求。但其余资源的参数未映射到客户端模型类参数

ruby-on-rails - 邪恶中的混合取向.pdf

html - 响应式 Bootstrap 不会预编译

ruby-on-rails - "_tag"on Rails 表单助手的意义是什么?

php - 从表 1 中获取行并从表 2 中创建或更新列

java - 是否有为 Spring 3 REST Controller 生成 JSON SMD 的解决方案?

java - 改造 android @Multipart 删除默认 header