Hi!

My problem instance's properties failed to share among the actions.
e.g. In action 'collect', I created an "CD" instance with some
"Album"s as its properties
using one-many relationship provided by rails API.
Before saving to the db, I just pass the 'CD' instance to action
'show', using @instance_var.
But I can't get properties information using 'cd.albums', it alway
return an empty array.

The reason why the objects do not get persisted is that modification
of objects is necessary.

Why can't I navigate through the relation and How can I pass around
the instance without?
--------------------------------------------------------------------

# model
class Cd < ActiveRecord::Base
        has_many :albums
end

class Album < ActiveRecord::Base
        belongs_to :cd
end

# in action "collect"
@cd = Cd.new
Dir.chdir("/media/cdrom")
        Dir.foreach(Dir.pwd) do | dir |
           logger.debug "found directory : [#{dir}]"
           if dir != "." && dir != ".."
                # collect album inf
                raw_info = dir
                @al = Album.new
                @al.name = dir.to_s
                @al.cd = @cd
                logger.debug "Checking album...@al.name}]'s belonging
[...@al.cd.volumn_name}]"
                logger.debug "Find album folder [#{dir}], thus cd
contains [...@cd.albums}]"
           end
        end
end

logging:
Processing MusicInventoryController#collect (for 127.0.0.1 at
2009-01-08 14:13:14) [GET]
found directory : [.]
found directory : [..]
found directory : [20090101]
Checking album[20090101]'s belonging [test]
Find album folder [20090101], thus cd contains []
Rendering music_inventory/show



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to