简体   繁体   English

如何在不使用控制器的情况下将表单数据提交并显示到Rails的另一页上?

[英]How to submit and display form data onto another page in rails without using controllers?

I have a form which takes various inputs and when clicking on submit it should display those params data on to another page. 我有一个接受各种输入的表单,单击“提交”时,应将这些参数数据显示在另一页上。 For example, I have a form called enter_invoice.html.erb 例如,我有一个名为enter_invoice.html.erb的表单

I have written the following html code for it. 我已经为它编写了以下html代码。

<%= form_tag('/generate_invoice', remote: true, multipart: true, type: :post )    
do |f| %>
 <input type="text" name="order[txnid]" placeholder="Enter your txnid" /><br>
 <input type="number" name="order[stamp_amount]" placeholder="Stamp amount" />
 <br>
 <input type="text" name="order[payment][created_at][strftime]" 
 placeholder="Payment Created at" /><br>
 <input type="text" name="order[payment][mode]" placeholder="Payment mode" />
 <br>
 <input type="text" name="order[user][profile][first_name]" placeholder="User 
 First name" /><br>

<input type="submit" class="submit action-button" /><br>

 <% end %>

Now I have another form called genrate_invoice.html.erb.The data I enter in enter_invoice should display on generate_invoice. 现在我有了另一个名为genrate_invoice.html.erb的表格。我在enter_invoice中输入的数据应该显示在generate_invoice上。

<html lang="">
<head>
    <meta charset="utf-8"> 
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
 </head>
<body style="margin:0 auto;padding:0;max-width:595px;font-family: 
 'PFBeauSansPro' 'Tahoma';font-weight:thin;font-size: 14px;background-size: 
  cover;ont-family: 'PFBeauSansPro';font-weight: thin !important;"> 
 TNXid : <%= @order.txnid %><br>
 Stamp_amount : <%= @order.stamp_amount %> <br/>
 Created_at : <%= @order.payment.created_at.strftime %> <br/>
 Address: <%= @order.address.address1 %><br/>
        :
        :

 </body>
 </html>

So how do I submit this data to be displayed on the generate_invoice.html.erb. 因此,我该如何提交要显示在generate_invoice.html.erb上的数据。

Newbie still in rails. 新手仍然处于困境。 Please guide me. 请指导我。

I think what you are trying to do is input data into a single object in a number of steps. 我认为您要尝试的步骤是将数据输入到单个对象中。 Avoiding controllers is not the best solution. 避免使用控制器不是最佳解决方案。

If you are new to rails, I'd suggest you have a look at the wicked gem . 如果您不熟悉铁轨,我建议您看看邪恶的宝石 That will help you build a multi-step input. 这将帮助您建立多步输入。

Alternatively, you can build you own solution by: 或者,您可以通过以下方式构建自己的解决方案:

  • adding a state machine to the object being updated (to track at what point in the process the object is), 在要更新的对象上添加状态机(以跟踪对象在过程中的哪个点),
  • using a form partial to match each object state, and modifying the view so that it picks the partial that matches the current object state. 使用局部窗体来匹配每个对象状态,并修改视图,以便它选择与当前对象状态匹配的局部。
  • and then use form objects to do things like validation this is consistent with the current state. 然后使用表单对象执行类似验证的操作,这与当前状态保持一致。 Have a look at the reform gem if you are unfamiliar with form objects. 如果您不熟悉表单对象,请看一下改革的瑰宝

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何显示评论表单提交而不使用AJAX刷新页面? - How to display comment form submit without refresh the page using AJAX? 如何在不使用数据库的情况下在html页面中单击提交按钮显示表单数据 - How to display form data onclick of submit button in html page without using Database 如何在不使用表单标签的情况下将值提交到另一页[JAVASCRIPT] - how to submit value to another page without using form tag [JAVASCRIPT] 如何在不重新加载页面的情况下提交表单数据 - How to submit a form data without reloading the page 如何在不提交表单的情况下在同一页面中显示表单数据? - How I can display the form data in the same page without submit the form? Rails form_tag提交数据而无需重新加载整个页面 - Rails form_tag submit data without reload the whole page 在不使用 PHP 的情况下单击表单中的提交(输入类型)后,如何使用 javascript 在页面上显示消息 - How to display a message on page using javascript after clicking on submit(input type) in a form without using PHP 如何在不刷新的情况下在页面上提交表单和更新元素,在 Rails 4 中 - How to submit form and update element on the page without refresh, in Rails 4 如何在不刷新页面的情况下将表单的数据提交到另一个函数? - How do I submit a form's data to another function without refreshing the page? 如何在使用 ajax 或 js 单击提交之前将一个表单数据填充到同一页面上的另一个表单中? - How to populate one form data into another form on same page before submit is clicked using ajax or js?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM