Hello all,
I have 2 tables calls and clients:
clients:
±----------±--------±-----±----±--------±---------------+
| Field | Type | Null | Key | Default | Extra |
±----------±--------±-----±----±--------±---------------+
| id | int(11) | | PRI | NULL | auto_increment |
| ivr_id | int(11) | YES | MUL | NULL | |
| is_online | char(1) | YES | | NULL | |
±----------±--------±-----±----±--------±---------------+
calls:
±------------±-------------±-----±----±--------±---------------+
| Field | Type | Null | Key | Default | Extra |
±------------±-------------±-----±----±--------±---------------+
| id | int(11) | | PRI | NULL | auto_increment |
| src | varchar(80) | YES | | NULL | |
| start | datetime | YES | | NULL | |
| ivr_id | int(11) | YES | MUL | NULL | |
| file_name | varchar(255) | YES | | NULL | |
±------------±-------------±-----±----±--------±---------------+
Here calls.ivr_id is the foreign key referring to clients.ivr_id
Corresponding models are :
class Call < ActiveRecord::Base
belongs_to :client, :foreign_key => “ivr_id”
def self.calls_and_is_online (from_time, to_time)
find (:first,
:conditions => [
“start > :from_time and start <= :to_time
and ivr_id <> 0
and file_name like ‘%wav’”,
{:from_time => from_time, :to_time => to_time}
])
end
end
class Client < ActiveRecord::Base
has_one :call, :foreign_key => “ivr_id”
end
My call_controller has a method
def get_calls_and_is_online
@date = Time.parse(params[:date])
@calls_and_is_online = Call.calls_and_is_online(@date, @date+1.day)
end
From my controller I can get all the details of call table with out
any problems. Now I want to get the is_online status of a call. The
rails book Chap: 18 says I can define some thing like price =
line_item.product.price, but in my case when I use <%=
@calls_and_is_online.client.is_online %> from my view, I get the error
NoMethodError in Call#get_calls_and_is_online
I know that I am missing some thing small, but not able to find what,
even after searching a lot… Any helping hand here is much
appreciated.
raj