加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 在rails中订购确认页面

发布时间:2020-12-17 04:03:14 所属栏目:百科 来源:网络整理
导读:我一直在尝试为我的rails应用程序创建一个订单确认页面,我不太确定如何以一种宁静的方式去做. 在this问题上有一些答案让我在那里中途,但问题是我不太确定如何在rails视图中设置表单,以便它将用户带到包含所有详细信息的确认页面而不是创建动作. 现在我的观点
我一直在尝试为我的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动作的表单.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读