[Rails] serialisation

Marc Isemann
Tue, 15 Aug 2006 23:09:45 -0000

the case:

i have two classes:

1)
class Contract < ActiveRecord::Base
  serialize :addons
end

2)
class Addon < ActiveRecord::Base
end

Now i do the following in contract_controller:

def create
 @contract = Contract.new(params[:contract])
 @contract.user_id = session[:user_id]
 @contract.customer_id = params[:customer_id]
 @contract.pending = 1
 @contract.addons = Array.new
end

def update
 @contract = Contract.find(params[:id])
 @contract.user_id = session[:user_id]
 @contract.customer_id = params[:customer_id]
 @contract.addons = Addon.find(:all, :conditions =>["user_id = ?
&& id
in (?) ",session[:user_id], Contract.get_addons(params[:addons])])
end

after create and update of a contract i have an serialized(YAML) array
of addons in my contract mysql-table.

the problem in view:

<% @contract.addons.each do |addon| %>
<%= addon.name %>
<% end %>

is just working under windows and not on linux!

errormessage:
undefined method `name'' for #<YAML::Object:0x407cc7b4>

I do have a name column in my addons table. Any solutions?

--
Posted via http://www.ruby-forum.com/.