3 Replies Latest reply on Oct 24, 2013 12:34 AM by Ruben Ruben

    Rhom: Can't access object's property after find

    Ruben Ruben

      I have a Uurdet class which inherits from PropertyBag, in which controller, i'm trying to do some stuff (filling missing fields before the object goes to the database, since there are some fields I don't want to bother the user with) under the create method:

       

      def create

           new_uurdet = @params['uurdet']

           ... # do stuff to fill missing attributes

       

       

           last_udt = Uurdet.find(:first, :conditions => {:persnr => Rho::RhoConnectClient.userName, :dagnr => new_uurdet["dagnr"], :weeknr =>                     new_uurdet["weeknr"]}, :order => "volgnr", :orderdir => "DESC")

         

           new_uurdet["volgnr"] = ((last_udt[:volgnr]).to_i+1).to_s 

       

          @uurdet = Uurdet.create(new_uurdet)

          redirect :action => :index

        end

       

      As you see, to fill the attribute "volgnr", I need to do a search on all Uurdets, and get the one with the biggest "volgnr", and assign my new_uurdet, with that number + 1.

       

      The find works fine, I get the object I want there, but last_udt[:volgnr] return always nil. I've used the debugger, and can confirm that the find works, but its when I try to access any of the propertys of the last_udt hash when I get always nil.

       

      I know new_uurdet is a regular Hash while last_udt is Uurdet object. Is this why I can't access elements in a Hash-fashioned way?

      How should I do this?

       

      Thanks!.