For that to work, you want `@page.id` not `self.id` Regards Jon
On 5 April 2011 22:55, DAZ <[email protected]> wrote: > Since I couldn't get the after :create hook to work, I tried putting > this ugly code in a handler: > > post '/new' do > @page = Page.create(params[:page]) > @page.url = '/mysite/' << self.id.to_s > @page.save > > This 'works', but strangely the id seems to be an object id, rather > than the id property from the database. What's going on here?? > > There must be a way of using a resource's id property to set another > property ... surely? > > cheers, > > DAZ > > On Apr 5, 5:47 pm, DAZ <[email protected]> wrote: >> > Is there any 'best practice' way of doing this sort of thing? >> >> > For example, do I use an after :create hook and then call self.save at >> > the end? >> > eg >> > after :create do >> > self.url ='/mysite/' << self.id.to_s >> > self.save >> > end >> >> Well the 'best practice' way is definitely not this way because it >> returns false - the resource is created but then is not saved >> afterwards and the url property is considered 'dirty' (what does that >> actually mean?? >> >> I'm puzzled by this! >> >> DAZ > > -- > You received this message because you are subscribed to the Google Groups > "DataMapper" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/datamapper?hl=en. > > -- You received this message because you are subscribed to the Google Groups "DataMapper" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/datamapper?hl=en.
