Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 用cocoon连接表数量(有多个通过)_Ruby On Rails_Associations_Jointable_Cocoon Gem - Fatal编程技术网

Ruby on rails 用cocoon连接表数量(有多个通过)

Ruby on rails 用cocoon连接表数量(有多个通过),ruby-on-rails,associations,jointable,cocoon-gem,Ruby On Rails,Associations,Jointable,Cocoon Gem,我没有发现任何与我的问题有关的东西。 我有这些模型: class Meal < ActiveRecord::Base has_many :meal_ingredients has_many :ingredients, through: :meal_ingredients accepts_nested_attributes_for :ingredients, :reject_if => :all_blank, :allow_destroy => true acce

我没有发现任何与我的问题有关的东西。 我有这些模型:

class Meal < ActiveRecord::Base
  has_many :meal_ingredients
  has_many :ingredients, through: :meal_ingredients
  accepts_nested_attributes_for :ingredients, :reject_if => :all_blank, :allow_destroy => true
  accepts_nested_attributes_for :meal_ingredients
end

class Ingredient < ActiveRecord::Base
  has_many :meal_ingredients
  has_many :meals, through: :meal_ingredients
end

class MealIngredient < ActiveRecord::Base
  belongs_to :meal
  belongs_to :ingredient
end
这就是我到目前为止得到的。。。我不认为主要的问题是由茧宝石引起的。我认为这是关于概念

情妇

Parameters: {"utf8"=>"✓", "authenticity_token"=>"dTYOiz8+pwNfwt432qhy7Yuj0hSVksj0bsTzxp8vD6QaupIJueSO1ASDkwiOB92qCiLO33Ke61aUBGbyvGZJfA==", "meal"=>{"name"=>"tests", "ingredients_attributes"=>{"1449471543091"=>{"name"=>"uva", "unit"=>"und", "carb"=>"1", "prot"=>"1", "fat"=>"1", "_destroy"=>"false"}}}, "meal_ingredient"=>{"quantity"=>"14"}, "commit"=>"Create Meal"}
看法 \u form.html.erb

<div class = "row">
  <div class= "col-md-10 col-md-offset-1">
    <%= simple_form_for(@meal) do |f| %>
      <%= f.error_notification %>
      <div class="form-inputs">
        <%= f.input :name %>
      </div>
      <h3>ingredientes</h3>
      <div id="ingredients">
        <%= f.simple_fields_for :ingredients do |ingredient| %>
          <%= render "ingredient_fields", :f => ingredient %>
        <% end %>
      </div>

      <div class="form-actions">
        <div><%= link_to_add_association 'adicionar ingrediente', f, :ingredients, :class => "btn btn-default" %></div>

        <div><%= f.button :submit, class: "btn btn-success" %></div>
      </div>
    <% end %>
  </div>
</div>
<%= render 'shared/errors', obj: @meal %>
<div class = "nested-fields">
  <table class= "table">
      <thead>
        <tr>
          <td>
            <%= f.label "Nome" %>
          </td>
          <td>
            <%= f.label "Unidade" %>
          </td>
          <td>
            <%= f.label "Carbo" %>
          </td>
          <td>
            <%= f.label "Prot" %>
          </td>
          <td>
            <%= f.label "Gordura" %>
          </td>
          <td>
            <%= f.label "Quantidade" %>
          </td>
          <td>
            <%= f.label "kcal" %>
          </td>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td scope="row" class="col-md-4">
            <%= f.text_field :name, required: true, class: "form-control" %>
          </td>
          <td class="col-md-2">
            <%= f.text_field :unit, required: true, class: "form-control" %>
          </td>
          <td class="col-md-1">
            <%= f.text_field :carb, required: true, :pattern => '^\d+(\.\d+)*$', title: "Apenas números separados por pontos", class: "form-control" %>
          </td>
          <td class="col-md-1">
            <%= f.text_field :prot, required: true, :pattern => '^\d+(\.\d+)*$', title: "Apenas números separados por pontos", class: "form-control" %>
          </td>
          <td class="col-md-1">
            <%= f.text_field :fat, required: true, :pattern => '^\d+(\.\d+)*$', title: "Apenas números separados por pontos", class: "form-control" %>
          </td>
          <td class="col-md-1">
            <%= fields_for @qtd do |f| %>
              <%= f.hidden_field :ingredient_id %>
              <%= f.number_field :quantity, required: true, :pattern => '^\d+(\.\d+)*$', title: "Apenas números separados por pontos", class: "form-control" %>
            <% end %>
          </td>          
          <td class="col-md-1">
          </td>
          <td class="col-md-1">
            <%= link_to_remove_association "remove item", f, :class => "btn btn-danger" %>
          </td>
        </tr>
      </tbody>
  </table>
</div>
<div class = "row">
  <div class= "col-md-10 col-md-offset-1">
    <%= simple_form_for(@meal) do |f| %>
      <%= f.error_notification %>
      <div class="form-inputs">
        <%= f.input :name %>
      </div>
      <h3>ingredientes</h3>
      <fieldset id="ingredients">
        <ol>
          <%= f.fields_for :meal_ingredients do |meal_ingredient| %>
            <%= render "meal_ingredient_fields", :f => meal_ingredient  %>
          <% end %>
        </ol>

        <div class="form-actions">
          <div><%= link_to_add_association 'adicionar ingrediente', f, :meal_ingredients, 'data-association-insertion-node' => "#ingredients ol", 'data-association-insertion-method' => "append", :wrap_object => Proc.new {|quantity| quantity.build_ingredient; quantity }, :class => "btn btn-default" %></div>
        </div>
      </fieldset>
      <div class="form-actions">
        <div><%= f.button :submit, class: "btn btn-success" %></div>
      </div>
    <% end %>
  </div>
</div>
<div class = "nested-fields">
  <table class= "table">
      <thead>
        <tr>
          <td>
            <%= f.label "Nome" %>
          </td>
          <td>
            <%= f.label "Unidade" %>
          </td>
          <td>
            <%= f.label "Carbo" %>
          </td>
          <td>
            <%= f.label "Prot" %>
          </td>
          <td>
            <%= f.label "Gordura" %>
          </td>
          <td>
            <%= f.label "Quantidade" %>
          </td>
          <td>
            <%= f.label "kcal" %>
          </td>
        </tr>
      </thead>
      <tbody>
        <tr>
          <%= f.fields_for :ingredient do |fi| %>
          <td scope="row" class="col-md-4">
            <%= fi.text_field :name, required: true, class: "form-control" %>
          </td>
          <td class="col-md-2">
            <%= fi.text_field :unit, required: true, class: "form-control" %>
          </td>
          <td class="col-md-1">
            <%= fi.text_field :carb, required: true, :pattern => '^\d+(\.\d+)*$', title: "Apenas números separados por pontos", class: "form-control" %>
          </td>
          <td class="col-md-1">
            <%= fi.text_field :prot, required: true, :pattern => '^\d+(\.\d+)*$', title: "Apenas números separados por pontos", class: "form-control" %>
          </td>
          <td class="col-md-1">
            <%= fi.text_field :fat, required: true, :pattern => '^\d+(\.\d+)*$', title: "Apenas números separados por pontos", class: "form-control" %>
          </td>
          <% end %>
          <td class="col-md-1">
            <%= f.number_field :quantity, required: true, :pattern => '^\d+(\.\d+)*$', title: "Apenas números separados por pontos", class: "form-control" %>

          </td>          
          <td class="col-md-1">
          </td>
          <td class="col-md-1">
            <%= link_to_remove_association "remove item", f, :class => "btn btn-danger" %>
          </td>
        </tr>
      </tbody>
  </table>
</div>

英格里登特斯
成分%>
“btn btn默认值”%>
\u component\u fields.html.erb

<div class = "row">
  <div class= "col-md-10 col-md-offset-1">
    <%= simple_form_for(@meal) do |f| %>
      <%= f.error_notification %>
      <div class="form-inputs">
        <%= f.input :name %>
      </div>
      <h3>ingredientes</h3>
      <div id="ingredients">
        <%= f.simple_fields_for :ingredients do |ingredient| %>
          <%= render "ingredient_fields", :f => ingredient %>
        <% end %>
      </div>

      <div class="form-actions">
        <div><%= link_to_add_association 'adicionar ingrediente', f, :ingredients, :class => "btn btn-default" %></div>

        <div><%= f.button :submit, class: "btn btn-success" %></div>
      </div>
    <% end %>
  </div>
</div>
<%= render 'shared/errors', obj: @meal %>
<div class = "nested-fields">
  <table class= "table">
      <thead>
        <tr>
          <td>
            <%= f.label "Nome" %>
          </td>
          <td>
            <%= f.label "Unidade" %>
          </td>
          <td>
            <%= f.label "Carbo" %>
          </td>
          <td>
            <%= f.label "Prot" %>
          </td>
          <td>
            <%= f.label "Gordura" %>
          </td>
          <td>
            <%= f.label "Quantidade" %>
          </td>
          <td>
            <%= f.label "kcal" %>
          </td>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td scope="row" class="col-md-4">
            <%= f.text_field :name, required: true, class: "form-control" %>
          </td>
          <td class="col-md-2">
            <%= f.text_field :unit, required: true, class: "form-control" %>
          </td>
          <td class="col-md-1">
            <%= f.text_field :carb, required: true, :pattern => '^\d+(\.\d+)*$', title: "Apenas números separados por pontos", class: "form-control" %>
          </td>
          <td class="col-md-1">
            <%= f.text_field :prot, required: true, :pattern => '^\d+(\.\d+)*$', title: "Apenas números separados por pontos", class: "form-control" %>
          </td>
          <td class="col-md-1">
            <%= f.text_field :fat, required: true, :pattern => '^\d+(\.\d+)*$', title: "Apenas números separados por pontos", class: "form-control" %>
          </td>
          <td class="col-md-1">
            <%= fields_for @qtd do |f| %>
              <%= f.hidden_field :ingredient_id %>
              <%= f.number_field :quantity, required: true, :pattern => '^\d+(\.\d+)*$', title: "Apenas números separados por pontos", class: "form-control" %>
            <% end %>
          </td>          
          <td class="col-md-1">
          </td>
          <td class="col-md-1">
            <%= link_to_remove_association "remove item", f, :class => "btn btn-danger" %>
          </td>
        </tr>
      </tbody>
  </table>
</div>
<div class = "row">
  <div class= "col-md-10 col-md-offset-1">
    <%= simple_form_for(@meal) do |f| %>
      <%= f.error_notification %>
      <div class="form-inputs">
        <%= f.input :name %>
      </div>
      <h3>ingredientes</h3>
      <fieldset id="ingredients">
        <ol>
          <%= f.fields_for :meal_ingredients do |meal_ingredient| %>
            <%= render "meal_ingredient_fields", :f => meal_ingredient  %>
          <% end %>
        </ol>

        <div class="form-actions">
          <div><%= link_to_add_association 'adicionar ingrediente', f, :meal_ingredients, 'data-association-insertion-node' => "#ingredients ol", 'data-association-insertion-method' => "append", :wrap_object => Proc.new {|quantity| quantity.build_ingredient; quantity }, :class => "btn btn-default" %></div>
        </div>
      </fieldset>
      <div class="form-actions">
        <div><%= f.button :submit, class: "btn btn-success" %></div>
      </div>
    <% end %>
  </div>
</div>
<div class = "nested-fields">
  <table class= "table">
      <thead>
        <tr>
          <td>
            <%= f.label "Nome" %>
          </td>
          <td>
            <%= f.label "Unidade" %>
          </td>
          <td>
            <%= f.label "Carbo" %>
          </td>
          <td>
            <%= f.label "Prot" %>
          </td>
          <td>
            <%= f.label "Gordura" %>
          </td>
          <td>
            <%= f.label "Quantidade" %>
          </td>
          <td>
            <%= f.label "kcal" %>
          </td>
        </tr>
      </thead>
      <tbody>
        <tr>
          <%= f.fields_for :ingredient do |fi| %>
          <td scope="row" class="col-md-4">
            <%= fi.text_field :name, required: true, class: "form-control" %>
          </td>
          <td class="col-md-2">
            <%= fi.text_field :unit, required: true, class: "form-control" %>
          </td>
          <td class="col-md-1">
            <%= fi.text_field :carb, required: true, :pattern => '^\d+(\.\d+)*$', title: "Apenas números separados por pontos", class: "form-control" %>
          </td>
          <td class="col-md-1">
            <%= fi.text_field :prot, required: true, :pattern => '^\d+(\.\d+)*$', title: "Apenas números separados por pontos", class: "form-control" %>
          </td>
          <td class="col-md-1">
            <%= fi.text_field :fat, required: true, :pattern => '^\d+(\.\d+)*$', title: "Apenas números separados por pontos", class: "form-control" %>
          </td>
          <% end %>
          <td class="col-md-1">
            <%= f.number_field :quantity, required: true, :pattern => '^\d+(\.\d+)*$', title: "Apenas números separados por pontos", class: "form-control" %>

          </td>          
          <td class="col-md-1">
          </td>
          <td class="col-md-1">
            <%= link_to_remove_association "remove item", f, :class => "btn btn-danger" %>
          </td>
        </tr>
      </tbody>
  </table>
</div>

“^\d+(\.\d+*$”,标题:“Apenas números separados por pontos”,类:“表单控制”%>
“^\d+(\.\d+*$”,标题:“Apenas números separados por pontos”,类:“表单控制”%>
“^\d+(\.\d+*$”,标题:“Apenas números separados por pontos”,类:“表单控制”%>
“^\d+(\.\d+*$”,标题:“Apenas números separados por pontos”,类:“表单控制”%>
“btn btn危险”%>

我也使用了cocoon,设置起来有些麻烦。我认为你必须认识到Rails比你想象的更聪明。您可以轻松地调用参数字符串上的save。只需确保所有参数都被接受即可。例如,您还需要:id作为配料属性(如果您也允许删除,还需要:\u destroy)。哦,还有,请松开联接表的嵌套_属性

我认为这样做应该奏效:

  def new
    @meal = Meal.new
  end

  def create
    @meal = Meal.new(meal_params)
    if @meal.save
      flash[:success] = "Refeição criada com sucesso!"
      redirect_to meals_path
    else
      render :new
    end
  end
private

    def meal_params
      params.require(:meal).permit(:name, :picture, ingredients_attributes: [:id, :name, :unit, :carb, :prot, :fat, :_destroy])
    end

如果没有,请发布包含主窗体和部分的视图。

我也使用了cocoon,设置它时遇到了一些问题。我认为你必须认识到Rails比你想象的更聪明。您可以轻松地调用参数字符串上的save。只需确保所有参数都被接受即可。例如,您还需要:id作为配料属性(如果您也允许删除,还需要:\u destroy)。哦,还有,请松开联接表的嵌套_属性

我认为这样做应该奏效:

  def new
    @meal = Meal.new
  end

  def create
    @meal = Meal.new(meal_params)
    if @meal.save
      flash[:success] = "Refeição criada com sucesso!"
      redirect_to meals_path
    else
      render :new
    end
  end
private

    def meal_params
      params.require(:meal).permit(:name, :picture, ingredients_attributes: [:id, :name, :unit, :carb, :prot, :fat, :_destroy])
    end
如果没有,请发布包含主窗体和部分的视图。

关注并查看应用程序。解决我的问题很容易,尽管我实际上不知道我在这里到底做了什么
“#配料ol”、“数据关联插入方法”=>“追加”、:wrap_object=>Proc.new{| quantity | quantity.build_配料;quantity},:class=>“btn btn default”%>

我讨厌这样编码,但这次我只是非常小心地按照流程进行…
如果有人已经将cocoon用于此目的,并且能够更好地解释,我和社区将非常感激:D
所做的更改:
型号

class MealIngredient < ActiveRecord::Base
  belongs_to :meal
  belongs_to :ingredient
  accepts_nested_attributes_for :ingredient, :reject_if => :all_blank
end
class MealingCredit:全部\u为空,则拒绝\u
结束
控制器

class MealsController < ApplicationController
  before_action :set_meal, only: [:edit, :update, :show]
  autocomplete :ingredients, :name

  def index
    @meals = Meal.order(updated_at: :desc).paginate(:page => params[:page], :per_page => 4)
  end

  def show
  end

  def new
    @meal = Meal.new
  end

  def create
    @meal = Meal.new(meal_params)
    if @meal.save
      flash[:success] = "Refeição criada com sucesso!"
      redirect_to meals_path
    else
      render :new
    end
  end

  def edit
  end

  def update
    if @meal.update(meal_params)
      flash[:success] = "Your meal was updated succesfully!"
      redirect_to meal_path(@meal)
    else
      render :edit
    end
  end

  private

    def meal_params
      params.require(:meal).permit(:name, :picture, :tcarb, :tprot, :tfat, :tkcal, meal_ingredients_attributes: [:quantity, ingredient_attributes: [:id, :name, :unit, :carb, :prot, :fat, :_destroy]])
    end


    def set_meal
      @meal = Meal.find(params[:id])
    end

end
class MealsControllerparams[:page],:per_page=>4)
结束
def秀
结束
def新
@新的
结束
def创建
@膳食=膳食。新(膳食参数)
如果@mean.save
flash[:success]=“Refeiço criada com successo!”
将\u重定向到\u路径
其他的
渲染:新
结束
结束
定义编辑
结束
def更新
如果@MEIN.update(膳食参数)
flash[:success]=“您的膳食已成功更新!”
重定向到膳食路径(@MEIN)
其他的
渲染:编辑
结束
结束
私有的
def膳食参数
参数require(:meat).permit(:name,:picture,:tcarb,:tprot,:tfat,:tkcal,膳食成分属性:[:数量,成分属性:[:id,:name,:unit,:carb,:prot,:fat,:\u destroy]]
结束
套餐
@膳食=膳食.查找(参数[:id])
结束
结束
视图
\u form.html.erb

<div class = "row">
  <div class= "col-md-10 col-md-offset-1">
    <%= simple_form_for(@meal) do |f| %>
      <%= f.error_notification %>
      <div class="form-inputs">
        <%= f.input :name %>
      </div>
      <h3>ingredientes</h3>
      <div id="ingredients">
        <%= f.simple_fields_for :ingredients do |ingredient| %>
          <%= render "ingredient_fields", :f => ingredient %>
        <% end %>
      </div>

      <div class="form-actions">
        <div><%= link_to_add_association 'adicionar ingrediente', f, :ingredients, :class => "btn btn-default" %></div>

        <div><%= f.button :submit, class: "btn btn-success" %></div>
      </div>
    <% end %>
  </div>
</div>
<%= render 'shared/errors', obj: @meal %>
<div class = "nested-fields">
  <table class= "table">
      <thead>
        <tr>
          <td>
            <%= f.label "Nome" %>
          </td>
          <td>
            <%= f.label "Unidade" %>
          </td>
          <td>
            <%= f.label "Carbo" %>
          </td>
          <td>
            <%= f.label "Prot" %>
          </td>
          <td>
            <%= f.label "Gordura" %>
          </td>
          <td>
            <%= f.label "Quantidade" %>
          </td>
          <td>
            <%= f.label "kcal" %>
          </td>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td scope="row" class="col-md-4">
            <%= f.text_field :name, required: true, class: "form-control" %>
          </td>
          <td class="col-md-2">
            <%= f.text_field :unit, required: true, class: "form-control" %>
          </td>
          <td class="col-md-1">
            <%= f.text_field :carb, required: true, :pattern => '^\d+(\.\d+)*$', title: "Apenas números separados por pontos", class: "form-control" %>
          </td>
          <td class="col-md-1">
            <%= f.text_field :prot, required: true, :pattern => '^\d+(\.\d+)*$', title: "Apenas números separados por pontos", class: "form-control" %>
          </td>
          <td class="col-md-1">
            <%= f.text_field :fat, required: true, :pattern => '^\d+(\.\d+)*$', title: "Apenas números separados por pontos", class: "form-control" %>
          </td>
          <td class="col-md-1">
            <%= fields_for @qtd do |f| %>
              <%= f.hidden_field :ingredient_id %>
              <%= f.number_field :quantity, required: true, :pattern => '^\d+(\.\d+)*$', title: "Apenas números separados por pontos", class: "form-control" %>
            <% end %>
          </td>          
          <td class="col-md-1">
          </td>
          <td class="col-md-1">
            <%= link_to_remove_association "remove item", f, :class => "btn btn-danger" %>
          </td>
        </tr>
      </tbody>
  </table>
</div>
<div class = "row">
  <div class= "col-md-10 col-md-offset-1">
    <%= simple_form_for(@meal) do |f| %>
      <%= f.error_notification %>
      <div class="form-inputs">
        <%= f.input :name %>
      </div>
      <h3>ingredientes</h3>
      <fieldset id="ingredients">
        <ol>
          <%= f.fields_for :meal_ingredients do |meal_ingredient| %>
            <%= render "meal_ingredient_fields", :f => meal_ingredient  %>
          <% end %>
        </ol>

        <div class="form-actions">
          <div><%= link_to_add_association 'adicionar ingrediente', f, :meal_ingredients, 'data-association-insertion-node' => "#ingredients ol", 'data-association-insertion-method' => "append", :wrap_object => Proc.new {|quantity| quantity.build_ingredient; quantity }, :class => "btn btn-default" %></div>
        </div>
      </fieldset>
      <div class="form-actions">
        <div><%= f.button :submit, class: "btn btn-success" %></div>
      </div>
    <% end %>
  </div>
</div>
<div class = "nested-fields">
  <table class= "table">
      <thead>
        <tr>
          <td>
            <%= f.label "Nome" %>
          </td>
          <td>
            <%= f.label "Unidade" %>
          </td>
          <td>
            <%= f.label "Carbo" %>
          </td>
          <td>
            <%= f.label "Prot" %>
          </td>
          <td>
            <%= f.label "Gordura" %>
          </td>
          <td>
            <%= f.label "Quantidade" %>
          </td>
          <td>
            <%= f.label "kcal" %>
          </td>
        </tr>
      </thead>
      <tbody>
        <tr>
          <%= f.fields_for :ingredient do |fi| %>
          <td scope="row" class="col-md-4">
            <%= fi.text_field :name, required: true, class: "form-control" %>
          </td>
          <td class="col-md-2">
            <%= fi.text_field :unit, required: true, class: "form-control" %>
          </td>
          <td class="col-md-1">
            <%= fi.text_field :carb, required: true, :pattern => '^\d+(\.\d+)*$', title: "Apenas números separados por pontos", class: "form-control" %>
          </td>
          <td class="col-md-1">
            <%= fi.text_field :prot, required: true, :pattern => '^\d+(\.\d+)*$', title: "Apenas números separados por pontos", class: "form-control" %>
          </td>
          <td class="col-md-1">
            <%= fi.text_field :fat, required: true, :pattern => '^\d+(\.\d+)*$', title: "Apenas números separados por pontos", class: "form-control" %>
          </td>
          <% end %>
          <td class="col-md-1">
            <%= f.number_field :quantity, required: true, :pattern => '^\d+(\.\d+)*$', title: "Apenas números separados por pontos", class: "form-control" %>

          </td>          
          <td class="col-md-1">
          </td>
          <td class="col-md-1">
            <%= link_to_remove_association "remove item", f, :class => "btn btn-danger" %>
          </td>
        </tr>
      </tbody>
  </table>
</div>

英格里登特斯
膳食成分%>
“#配料ol”,“数据关联插入方法”=>“追加”,:wrap_object=>Proc.new{{| quantity | quantity.build_配料;quantity},:class=>“btn btn default”%>
\u餐\配料\字段.html.erb

<div class = "row">
  <div class= "col-md-10 col-md-offset-1">
    <%= simple_form_for(@meal) do |f| %>
      <%= f.error_notification %>
      <div class="form-inputs">
        <%= f.input :name %>
      </div>
      <h3>ingredientes</h3>
      <div id="ingredients">
        <%= f.simple_fields_for :ingredients do |ingredient| %>
          <%= render "ingredient_fields", :f => ingredient %>
        <% end %>
      </div>

      <div class="form-actions">
        <div><%= link_to_add_association 'adicionar ingrediente', f, :ingredients, :class => "btn btn-default" %></div>

        <div><%= f.button :submit, class: "btn btn-success" %></div>
      </div>
    <% end %>
  </div>
</div>
<%= render 'shared/errors', obj: @meal %>
<div class = "nested-fields">
  <table class= "table">
      <thead>
        <tr>
          <td>
            <%= f.label "Nome" %>
          </td>
          <td>
            <%= f.label "Unidade" %>
          </td>
          <td>
            <%= f.label "Carbo" %>
          </td>
          <td>
            <%= f.label "Prot" %>
          </td>
          <td>
            <%= f.label "Gordura" %>
          </td>
          <td>
            <%= f.label "Quantidade" %>
          </td>
          <td>
            <%= f.label "kcal" %>
          </td>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td scope="row" class="col-md-4">
            <%= f.text_field :name, required: true, class: "form-control" %>
          </td>
          <td class="col-md-2">
            <%= f.text_field :unit, required: true, class: "form-control" %>
          </td>
          <td class="col-md-1">
            <%= f.text_field :carb, required: true, :pattern => '^\d+(\.\d+)*$', title: "Apenas números separados por pontos", class: "form-control" %>
          </td>
          <td class="col-md-1">
            <%= f.text_field :prot, required: true, :pattern => '^\d+(\.\d+)*$', title: "Apenas números separados por pontos", class: "form-control" %>
          </td>
          <td class="col-md-1">
            <%= f.text_field :fat, required: true, :pattern => '^\d+(\.\d+)*$', title: "Apenas números separados por pontos", class: "form-control" %>
          </td>
          <td class="col-md-1">
            <%= fields_for @qtd do |f| %>
              <%= f.hidden_field :ingredient_id %>
              <%= f.number_field :quantity, required: true, :pattern => '^\d+(\.\d+)*$', title: "Apenas números separados por pontos", class: "form-control" %>
            <% end %>
          </td>          
          <td class="col-md-1">
          </td>
          <td class="col-md-1">
            <%= link_to_remove_association "remove item", f, :class => "btn btn-danger" %>
          </td>
        </tr>
      </tbody>
  </table>
</div>
<div class = "row">
  <div class= "col-md-10 col-md-offset-1">
    <%= simple_form_for(@meal) do |f| %>
      <%= f.error_notification %>
      <div class="form-inputs">
        <%= f.input :name %>
      </div>
      <h3>ingredientes</h3>
      <fieldset id="ingredients">
        <ol>
          <%= f.fields_for :meal_ingredients do |meal_ingredient| %>
            <%= render "meal_ingredient_fields", :f => meal_ingredient  %>
          <% end %>
        </ol>

        <div class="form-actions">
          <div><%= link_to_add_association 'adicionar ingrediente', f, :meal_ingredients, 'data-association-insertion-node' => "#ingredients ol", 'data-association-insertion-method' => "append", :wrap_object => Proc.new {|quantity| quantity.build_ingredient; quantity }, :class => "btn btn-default" %></div>
        </div>
      </fieldset>
      <div class="form-actions">
        <div><%= f.button :submit, class: "btn btn-success" %></div>
      </div>
    <% end %>
  </div>
</div>
<div class = "nested-fields">
  <table class= "table">
      <thead>
        <tr>
          <td>
            <%= f.label "Nome" %>
          </td>
          <td>
            <%= f.label "Unidade" %>
          </td>
          <td>
            <%= f.label "Carbo" %>
          </td>
          <td>
            <%= f.label "Prot" %>
          </td>
          <td>
            <%= f.label "Gordura" %>
          </td>
          <td>
            <%= f.label "Quantidade" %>
          </td>
          <td>
            <%= f.label "kcal" %>
          </td>
        </tr>
      </thead>
      <tbody>
        <tr>
          <%= f.fields_for :ingredient do |fi| %>
          <td scope="row" class="col-md-4">
            <%= fi.text_field :name, required: true, class: "form-control" %>
          </td>
          <td class="col-md-2">
            <%= fi.text_field :unit, required: true, class: "form-control" %>
          </td>
          <td class="col-md-1">
            <%= fi.text_field :carb, required: true, :pattern => '^\d+(\.\d+)*$', title: "Apenas números separados por pontos", class: "form-control" %>
          </td>
          <td class="col-md-1">
            <%= fi.text_field :prot, required: true, :pattern => '^\d+(\.\d+)*$', title: "Apenas números separados por pontos", class: "form-control" %>
          </td>
          <td class="col-md-1">
            <%= fi.text_field :fat, required: true, :pattern => '^\d+(\.\d+)*$', title: "Apenas números separados por pontos", class: "form-control" %>
          </td>
          <% end %>
          <td class="col-md-1">
            <%= f.number_field :quantity, required: true, :pattern => '^\d+(\.\d+)*$', title: "Apenas números separados por pontos", class: "form-control" %>

          </td>          
          <td class="col-md-1">
          </td>
          <td class="col-md-1">
            <%= link_to_remove_association "remove item", f, :class => "btn btn-danger" %>
          </td>
        </tr>
      </tbody>
  </table>
</div>

“^\d+(\.\d+*$”,标题:“Apenas números separados por pontos”,类:“表单控制”%>
“^\d+(\.\d+*$”,标题:“Apenas números separados por pontos”,类:“表单控制”%>
“^\d+(\.\d+*$”,标题:“Apenas números separados por pontos”,类:“表单控制”%>
“^\d+(\.\d+*$”,标题:“Apenas números separados por pontos”,类:“表单控制”%>
“btn btn危险”%>