forked from railsadminteam/rails_admin
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding destroy config section and support for custom destroy methods …
…on models
- Loading branch information
Showing
13 changed files
with
243 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,3 +20,4 @@ spec/dummy_app/log/*.log | |
tmp/**/* | ||
/.emacs.desktop | ||
.idea/*.xml | ||
*~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
require 'rails_admin/config/base' | ||
|
||
module RailsAdmin | ||
module Config | ||
module Sections | ||
# Configuration of the destroy view | ||
class Destroy < RailsAdmin::Config::Base | ||
|
||
# Defines if the objects will be destroyed using a custom_method | ||
register_instance_option(:soft_destroy) do | ||
false | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class Club < ActiveRecord::Base | ||
validates_presence_of(:name) | ||
|
||
def custom_destroy | ||
update_attribute(:disabled, true) | ||
|
||
@destroyed = true | ||
freeze | ||
end | ||
end | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class Coach < ActiveRecord::Base | ||
validates_presence_of(:name) | ||
|
||
def soft_destroy | ||
update_attribute(:disabled, true) | ||
|
||
@destroyed = true | ||
freeze | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,16 @@ | ||
RailsAdmin.config do |c| | ||
c.excluded_models << RelTest | ||
|
||
c.model Coach do | ||
destroy do | ||
soft_destroy true | ||
end | ||
end | ||
|
||
c.model Club do | ||
destroy do | ||
soft_destroy :custom_destroy | ||
end | ||
end | ||
|
||
end |
14 changes: 14 additions & 0 deletions
14
spec/dummy_app/db/migrate/20110317161401_create_coaches_migration.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class CreateCoachesMigration < ActiveRecord::Migration | ||
def self.up | ||
create_table :coaches do |t| | ||
t.string :name | ||
t.boolean :disabled | ||
|
||
t.timestamps | ||
end | ||
end | ||
|
||
def self.down | ||
drop_table :coaches | ||
end | ||
end |
14 changes: 14 additions & 0 deletions
14
spec/dummy_app/db/migrate/20110317161602_create_clubs_migration.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class CreateClubsMigration < ActiveRecord::Migration | ||
def self.up | ||
create_table :clubs do |t| | ||
t.string :name | ||
t.boolean :disabled | ||
|
||
t.timestamps | ||
end | ||
end | ||
|
||
def self.down | ||
drop_table :clubs | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters