【发布时间】:2015-09-17 21:22:44
【问题描述】:
我定义了一个辅助方法来预填充嵌套模型。
module MealsHelper
def setup_meal( meal )
add_recipes meal, 3
end
def add_recipes( meal, number )
number.times { meal.recipes.build }
end
end
然后我将它添加到我的控制器中:
class MealsController < ApplicationController
before_action :set_meal, only: [:show, :edit, :update, :destroy]
helper MealsHelper
然后我从我的表单中调用它:
<%= form_for(setup_meal(@meal)) do |f| %>
现在我明白了:
undefined method `model_name' for 3:Fixnum
为什么 rails 会尝试为 Fixnum 寻找模型?
如果我跳过辅助方法,错误就会消失:
<%= form_for(@meal) do |f| %>
【问题讨论】:
标签: ruby-on-rails ruby forms ruby-on-rails-4