开发者

rails multiple input record

开发者 https://www.devze.com 2023-03-05 08:16 出处:网络
I\'m new to rails. I have some question that\'s been quite a headache to me, so here it is: For example i have this controller & view:

I'm new to rails. I have some question that's been quite a headache to me, so here it is:

For example i have this controller & view:

Controller:

class OrdersController < ApplicationController
  def new
    @Order = Order.new
  end 

  def create
    @Order = Order.new(params[:order])
    if @Order.save
      flash[:notice] = "Successfully created order."
      redirect_to @Order
    else
      render :action => 'new'
    end
  end

View:

<% title "Menu Order" %>
<%= form_for @Order do |f| %>
  <%= f.error_messages %>

<div id="form-order">
  <p>
    <%= f.label :name%><br />
    <%= f.text_field :name, %>
  </p>
  <p>
    <%= f.label :menu_order %><br />
    <%= f.text_field :menu_order  %>
  </p>   
</div>
<%= f.submit %>

So my question is :

before displaying the form above, I want to have a text_field_tag that specify how many forms (roughly said, duplicate the form div) I want to generate based on count, and then insert the data to the database simultaneously, the ide开发者_运维技巧a is to speed things up, so that the user don't have to input the data only one at a time, but multiple record at single submit

How do I do that?

0

精彩评论

暂无评论...
验证码 换一张
取 消