テンプレートにこれがあります
<% @clients.each do |client| %>
<li><%= link_to client.name, :controller => "client", :action => "show", :id => client.id %></li>
<%=YAML::dump(client.lastfull)%>
<% end %>
クライアントは次のようになります。
class Client < ActiveRecord::Base
set_table_name 'client'
alias_attribute :id, :clientid
set_primary_key :clientid
has_many :jobs, :foreign_key => 'clientid', :order => 'starttime DESC'
def lastfull
jobs.first
end
end
これは機能し、これが出力されます:
--- !ruby/object:Job attributes: jobid: "81" name: dobrak comment: "" endtime: 2012-06-20 10:15:04
しかし、属性のいずれかを読み込もうとすると、エラーが発生します。
undefined method `jobid' for nil:NilClass
ジョブクラス:
class Job < ActiveRecord::Base
attr_accessor :jobid
set_table_name 'job'
belongs_to :client
has_one :status, :primary_key => 'jobstatus', :foreign_key => 'jobstatus'
end
属性を返すメソッドjobidを追加し、attr_accessorを追加しようとしましたが、何も機能しませんでした。助言がありますか?ありがとうございました。
レール2.3.5