I would like to apply logical delete in my application(Instead of
permanently deleting a record just have been marked as deleted). I have
Added *available* column to all tables with default value *true*. Now I
want common place to write the following code for all models.


1.

Write the instance method which make 'available' column value false when user clicks on destroy link.

2.

Merge the 'available=true' condition to all ActiveRecord's queries while fetching the records.


With reference Rails extending ActiveRecord::Base<http://stackoverflow.com/questions/2328984/rails-extending-activerecordbase>,
I decided to use monkey patch to do above. Created monkey patch file in
config/initializer/active_record_patch.rb:

class ActiveRecord::Base
def inactive
update_attribute(:available, false)
end

default_scope :available => true
end

Getting following error when add the default_scope

*/gems/ruby-1.9.2-p290/gems/activerecord-3.0.9/lib/active_record/base.rb:1212:in
class_of_active_record_descendant': undefined methodabstract_class?' for
Object:Class (NoMethodError)*


--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/LSZ_4NOqFE4J.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedJul 25, '12 at 2:35p
activeJul 25, '12 at 2:35p
posts1
users1
websiterubyonrails.org
irc#RubyOnRails

1 user in discussion

Manivannan J: 1 post

People

Translate

site design / logo © 2021 Grokbase