How to call a method on an object in a nested form in Ruby on Rails 3?

前端 未结 1 745
别那么骄傲
别那么骄傲 2021-01-21 19:03

I have these two models

class Invoice < ActiveRecord::Base
  has_many :items      
  accepts_nested_attributes_for :items
  ...
end

class Item < ActiveRec         


        
相关标签:
1条回答
  • 2021-01-21 19:33

    You are calling a method not on your model object, but on f, which is a form helper (ActionView::Helpers::FormBuilder). Error message gives a hint to this.

    To call on the item, you need to replace

    <%= f.total %>
    

    with

    <%= f.object.total %>
    
    0 讨论(0)
提交回复
热议问题