Hi Here I am trying to get the details of changed fields in update method I got those fields by changes method. #obj.changes But problem is that I got changes in following ways even when I am not updating anything. obj.changes {"address"=>[nil, ""]} This is what I don''t want. I want only those changes which are text to blank or blank to text or text to text.. Can anybody help me ? Thanks Brijesh Shah -- Posted via http://www.ruby-forum.com/. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 3 January 2011 10:12, Brijesh Shah <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hi > > Here I am trying to get the details of changed fields in update method > > I got those fields by changes method. #obj.changes > > But problem is that I got changes in following ways even when I am not > updating anything. > > obj.changes > {"address"=>[nil, ""]} > > This is what I don''t want. I want only those changes which are text to > blank or blank to text or text to text..Just filter out the ones where the two array entries are nil and "". Note that blank? will probably be useful here. Colin -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Colin Law wrote in post #971987:> > Just filter out the ones where the two array entries are nil and "". > Note that blank? will probably be useful here. > > ColinThanks for reply. But how can I filter this one? Currently I am checking the field change and avoid nil to blank changes. like if !obj.changes["address] != [nil,""] ---More ---- end Note: There are multiple fields to check. Thanks Brijesh Shah -- Posted via http://www.ruby-forum.com/. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 3 January 2011 12:47, Brijesh Shah <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Colin Law wrote in post #971987: > >> >> Just filter out the ones where the two array entries are nil and "". >> Note that blank? will probably be useful here. >> >> Colin > > Thanks for reply. But how can I filter this one? > Currently I am checking the field change and avoid nil to blank changes. > > like if !obj.changes["address] != [nil,""] > ---More ---- > end > > Note: There are multiple fields to check.Run through the hash first removing items for which both elements of its array respond true to .blank? Have a look at Hash.delete_if for example. Colin -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hi Thanks Colin. This should works fine.. Thanks Brijesh Shah -- Posted via http://www.ruby-forum.com/. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Maybe Matching Threads
- Princely Plugin: get nil.size error
- NoMethodError (undefined method `service_options' for nil:NilClass)
- Authlogic + Rails3 - undefined method `Login' for nil:NilClass
- NoMethodError (private method `chomp' called for nil:NilClas
- hash in controller is nil after submitting form