Last active
December 20, 2015 03:19
-
-
Save celeryclub/6062958 to your computer and use it in GitHub Desktop.
Example RailsAdmin configuration with a nested resource.
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
# app/models/image.rb | |
class Image < ActiveRecord::Base | |
belongs_to :term | |
def serializable_hash(options = nil) | |
hash = super | |
hash.delete_if { |k, v| v.blank? } | |
hash.delete('filename') | |
hash['file_path'] = self.filename.present? ? self.filename.url.split('/').last(2).join('/') : nil | |
hash.except('created_at', 'updated_at') | |
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
# config/initializers/rails_admin.rb | |
RailsAdmin.config do |config| | |
### snip | |
config.audit_with :history, 'User' | |
### snip | |
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
# app/models/term.rb | |
class Term < ActiveRecord::Base | |
has_many :images, :order => 'preferred DESC', :dependent => :destroy | |
accepts_nested_attributes_for :images, :allow_destroy => true | |
def serializable_hash(options = nil) | |
hash = super | |
hash['title'] ||= "#{self.note_2} #{self.note_1}" | |
hash.delete('audio') | |
hash['audio_path'] = self.audio.present? ? self.audio.url.split('/').last(2).join('/') : nil | |
hash.except('slug', 'created_at', 'updated_at', 'audio_notes', 'image_notes', 'note_1', 'note_2') | |
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
# app/models/user.rb | |
class User < ActiveRecord::Base | |
devise :database_authenticatable, | |
:recoverable, :rememberable, :trackable, :validatable | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment