0

I have an apartment class with an attr_accessor called checkin (doesn't need to be saved in DB)

class Apartment < ActiveRecord::Base
  attr_accessible :checkin
  attr_accessor :checkin

  has_many :rooms
  has_many :beds through: rooms
end

In my controller i'm setting checkin's value

def show
  @apartment.update_attributes(checkin: session[:checkin])
end

When the page renders i call a method of bed which tries to access self.room.apartment.checkin but i am getting nil value

This method is called by a method in apartment. I've debbuged the call and when i am inside the apartment model the checkin variable has a value. Why am I getting nil when calling from bed? Thanks to all helpers!

4

1 回答 1

0

你说你是从bed- 如在bed.apartment.checkin

如果这是真的,那就是你的问题:你只设置checkin了保存在 instance variable 中的 Apartment 实例@apartment。那个与您通过 接收的实例不同bed.apartment.checkin

于 2013-12-08T10:49:14.880 回答