0
我有以下嵌套形式:在嵌套形式訪問對象
<%= form_for @contrat,:url => backend_orders_update_report_url(@contrat) do |f| %>
<%= f.fields_for :contrat_lines do |fcl| %>
<%= fcl.object.inspect %>
<% end %>
<% end %>
輸出如下:
nil
在嵌套形式我想顯示幾個元素不是作爲形式但作爲原始文本和一些表單字段。通常在通過執行f.object.name的形式中,我將訪問該名稱並能夠按照我的意願顯示它。但是,在這裏,如果我做fcl.object,只有零。它應該顯示contrat_line對象的檢查。
是否有可能以嵌套形式訪問數據?
編輯:
控制器動作:
def show_report
@contrat = Contrat.find(params[:id])
end
這裏是車型會是什麼樣的beggining的關係:
ContratLine:
class ContratLine < ActiveRecord::Base
include Priceable
belongs_to :contrat
belongs_to :good
#a enlever ici et dans la base
attr_accessible :active_start,:active,:good_id,:pricing,:contrat
validates :active_start, :presence=> true,:if => "active"
validate :active_start_smaller_than_active_stop
validate :active_start_day_cannot_be_greater_than_28
has_one :pricing, :as => :priceable, :dependent => :delete
before_validation :convert_month_year_to_date
after_save :set_user_subscription_date
Contrat:
class Contrat < ActiveRecord::Base
has_many :contrat_lines, :dependent => :delete_all
belongs_to :user
attr_accessible :user_id,:pricing_id,:state,:adresse_id,:adresse,:payment,:adresse_attributes,:automatic,:start_date,:end_date
enum_attr :state, %w(basket waiting_data to_confirm paid) do
labels :basket=>'Panier', :to_confirm=>'Non payé',:paid=>'Payé'
end
enum_attr :payment, %w(debit_card wire_transfer cheque direct_debit)
belongs_to :adresse
accepts_nested_attributes_for :adresse, :allow_destroy => true
scope :by_state, lambda { |state| where("state = ?",state) }
scope :last_automatic, where("automatic = true").order("invoice_date DESC")
scope :last_with_adresse, where("state != 'basket'").order("invoice_date DESC")
before_validation :set_numbers
你的模型看起來怎麼樣?你可以發佈一些模型代碼嗎? – 2013-02-10 11:20:10