Ruby on Rails:在创建对象之前创建确认视图 [英] Ruby on Rails: Create confirmation view before creating the object

查看:40
本文介绍了Ruby on Rails:在创建对象之前创建确认视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下用于创建产品的代码:

I have the below code for creating a product:

def create
    @customer = Customer.find(params[:customer_id])
    @product = @customer.products.build(params[:product])

    respond_to do |format|
      if @product.save
        format.html { redirect_to customer_products_path(@customer), notice: 'Product was successfully created.' }
      else
        format.html { render action: "new" }
        format.json { render json: customer_products_path.errors, status: :unprocessable_entity }
      end
    end
  end

生成我使用的表单:

<%= form_for([@customer, @product]) do |f| %>

现在,我想知道,在将数据保存到数据库之前,如何将使用转移到单独的确认页面.还带有编辑链接,因此如果需要,用户可以进行更改并最终提交记录.

Now, I am wondering, how can I transfer the use to a separate confirmation page before saving the data to the DB. Also with an edit link, so if needed the user can make changes and submit the records finally.

我查看了有关 stackoverflow 的其他问题,但无法创建我想要的内容.任何指导表示赞赏.

I looked at other questions on stackoverflow, but was unable to create what I want. Any guidance is appreciated.

推荐答案

您可以使用带参数的新按钮:

You can use a new button with a parameter:

  <%= f.submit %>
  <%= f.submit "Preview", :name => 'preview' %>

在您的控制器中,在创建操作中:

and in your controller, in create action:

if params[:preview]
@product = Product.new(params[:product])
render 'products/previw'
else
# save your object
end

并创建一个新的部分进行预览.

and create a new partial for preview.

这篇关于Ruby on Rails:在创建对象之前创建确认视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆