SlideShare a Scribd company logo
RailsAdmin
Overview & Best practices
mercredi 7 août 13
14 years ago
Acceptable in the 90’
mercredi 7 août 13
Data Admin,
stand-alone
• + Pros
• Reliable
• Powerful
• - Cons
• No business rules
whatsoever
mercredi 7 août 13
mercredi 7 août 13
Data Admin,
in the application
• + Pros
• Leverages the whole
application or some parts for
business rules etc.
• - Cons
• No direct (fast) DB
administration
• Your code?
In theory...
mercredi 7 août 13
• Admin generator
• Immediate startup
• Steep learning curve
• Extensible
• Powerful when leverages Rails
Models and Cancan
• Admin builder
• Slower startup
• Simple DSL
• Usable
• Good for ad-hoc admin building
when Models/Cancan rules don’t
infer the UI
RailsAdmin ActiveAdmin
Grain of salt, common sense, etc.
mercredi 7 août 13
Pitfall
• ActiveAdmin lets you do the work
• => with some help from Formtastic :/
• RailsAdmin shortcuts ActiveModel
• => Complex custom code laying on the
ORMs :/
• But hey! it works®*
ActiveModel does not provide anything
for associations!
* Unless you screwed up your
models associations definitions
mercredi 7 août 13
Minimum installation
• rails new new_app
• rails g model blog::post
title:string content:text
• rails g model blog::comment
content:text post:belongs_to
• gem ‘rails_admin’
• mount RailsAdmin::Engine => ‘’
mercredi 7 août 13
Big picture
• Actions
• Map routing to templates and controller
• Sections
• Map field configuration to each action
• Fields
• Handle fields configurations
mercredi 7 août 13
Actions-Sections
CRUD mapping
• new => new < edit < base
• edit => update < edit < base
• edit/new nested => nested < edit < base
• edit/new modal => modal < edit < base
• index => list < base
• export => export < base
mercredi 7 août 13
Example
mercredi 7 août 13
The issue...
• Never-ending list of
section/fields definitions
mercredi 7 août 13
Solutions
• Use configure as much as you can (doesn’t
force the field list in opt-in mode)
• Use order
• Move each model configuration to a
rails_admin block in class definition
• Hide fields you don’t need instead of listing
them (less overhead usually)
mercredi 7 août 13
Associations
mercredi 7 août 13
The associations
• has_many => nested
• has_one => nested
• belongs_to => modal
• has_many :through => modal
• has_and_belong_to_many => modal
• It makes sense®
mercredi 7 août 13
Back to our models...
mercredi 7 août 13
You tell your ORM
about it
mercredi 7 août 13
Stay on the Golden path	

• Convention over configuration!
• RailsAdmin gets as much intel as it
can from your models:
• Fields
• Associations
• Validations
• Don’t configure RailsAdmin when
you can tweak your app to Rails’
best standards!
mercredi 7 août 13
But wait! Admin!
Passwords and stuff!
• gem ‘devise’
• rails g devise:install
• rails g devise user
• rails g migration add_user_id_to_blog_posts user:belongs_to
• config/rails_admin.rb:
mercredi 7 août 13
Who am I?
mercredi 7 août 13
This is called authentication.
Do you have authorization?
• gem ‘cancan’
• rails g migration add_profile_to_users profile:string
• config/rails_admin.rb:
• rails g cancan:ability
mercredi 7 août 13
Some other profiles
• Admin can do anything
• Writer can
• access rails_admin
• access the dashboard
• CRUD Blog::Post that he owns
• for new posts, user_id will be forced to his id
mercredi 7 août 13
Ok, what do I get for my
writers ?
mercredi 7 août 13
At last, some RailsAdmin
field configuration!
mercredi 7 août 13
Deal with serialized
fields
• rails g migration
add_metadata_to_blog_posts
metadata:text
• models/blog/post.rb
mercredi 7 août 13
Now what?
• It’s error prone :(
• It’s ugly :(
• It’s not user friendly :(
• It’s dangerous :(
• What should I do?
mercredi 7 août 13
Use some ‘virtual’ fields?
• You don’t need your object to respond to ‘block’ !
• You can create RailsAdmin fields out of the blue
• You just need to define value and parse_input methods (in &
out the form)
• allowed_methods lets you modify the mass-assignable params
on the object (safety)
mercredi 7 août 13
Say I need another one
like ‘block’?
• Let’s create a metadata RailsAdmin field type,
in our application
• lib/rails_admin/metadata.rb
mercredi 7 août 13
Time to leverage
No pollution in the model!
mercredi 7 août 13
Some actions?
mercredi 7 août 13
I need to publish my posts!
Define an action, then use it
mercredi 7 août 13
Then the view part, simple stuff
The view goes to rails_admin/
main/publish.slim
Then add some translations for
proper integration
mercredi 7 août 13
I’m in trouble
• Check that your models are ok (rails c)
• bundle open rails_admin
• trace @abstract_model, @object in actions
• trace @abstract_model, bindings[:object] in
fields
mercredi 7 août 13
Someone said I need tests, I probably need tests, did I
say I need tests?
https://github.com/sferik/rails_admin/wiki/Rspec-with-capybara-examples
mercredi 7 août 13
Thanks for listening!
Full example code
https://github.com/bbenezech/blog_admin
benoit.benezech@gmail.com
@bbenezech github/Skype/twitter
Freelance
mercredi 7 août 13

More Related Content

PDF
How Can AI Transform the Software Development Process?
PPTX
ARTIFICIAL INTELLIGENCE IN SOFTWARE ENGINEERING
PDF
Django Best Practices
PDF
ORM: Object-relational mapping
PDF
An Introduction to Software Architecture
PPTX
MySQL Database with phpMyAdmin
PPTX
AI in Software Development.pptx
How Can AI Transform the Software Development Process?
ARTIFICIAL INTELLIGENCE IN SOFTWARE ENGINEERING
Django Best Practices
ORM: Object-relational mapping
An Introduction to Software Architecture
MySQL Database with phpMyAdmin
AI in Software Development.pptx

What's hot (20)

PPTX
Angularjs PPT
PDF
Spring Data JPA from 0-100 in 60 minutes
PPTX
Object oreinted php | OOPs
PDF
Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023
PDF
ACM DBPL Keynote: The Graph Traversal Machine and Language
PPTX
Modules in AngularJs
PPSX
Collections - Maps
PDF
ES6 presentation
PDF
Ksug2015 - JPA1, JPA 소개
PPTX
PPTX
PPT
Java Script ppt
PPTX
Dependency injection - the right way
PDF
애플리케이션 아키텍처와 객체지향
PPTX
Express js
PDF
Adobe AEM - From Eventing to Job Processing
PDF
PPTX
Functional Patterns with Java8 @Bucharest Java User Group
PPTX
Understanding react hooks
PDF
Spring annotation
Angularjs PPT
Spring Data JPA from 0-100 in 60 minutes
Object oreinted php | OOPs
Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023
ACM DBPL Keynote: The Graph Traversal Machine and Language
Modules in AngularJs
Collections - Maps
ES6 presentation
Ksug2015 - JPA1, JPA 소개
Java Script ppt
Dependency injection - the right way
애플리케이션 아키텍처와 객체지향
Express js
Adobe AEM - From Eventing to Job Processing
Functional Patterns with Java8 @Bucharest Java User Group
Understanding react hooks
Spring annotation
Ad

Viewers also liked (20)

PDF
RailsAdmin - the right way of doing data administration with Rails 3
PDF
Rails Admin - Guru SP
PDF
Calendário de abastecimento - março (alterado)
PDF
軽い! 速い! サーバを選ばない! Ruby製CMS "nanoc"
PPTX
SF1 - Apex Development Best Practises
PDF
Active admin
PDF
Globo.com - migração do player flash para html5
PDF
Amazon S3とnanocで作る 安い・落ちないwebサイト
PPTX
Weblogic Server
PPT
Be2Awards and Be2Talks 2013 - event slides
TXT
Cookies
PDF
Condor overview - glideinWMS Training Jan 2012
PDF
EdCamp News & UpDates
PDF
saic annual reports 2003
KEY
WebLion Hosting: Leveraging Laziness, Impatience, and Hubris
PDF
ITIL v3 story
PDF
Securing the e health cloud
PDF
The Django Book - Chapter 6 the django admin site
PDF
Uhy global directory-2013
PDF
For Self-Published Authors. Creative Content Opps. Bookexpo America uPublishU...
RailsAdmin - the right way of doing data administration with Rails 3
Rails Admin - Guru SP
Calendário de abastecimento - março (alterado)
軽い! 速い! サーバを選ばない! Ruby製CMS "nanoc"
SF1 - Apex Development Best Practises
Active admin
Globo.com - migração do player flash para html5
Amazon S3とnanocで作る 安い・落ちないwebサイト
Weblogic Server
Be2Awards and Be2Talks 2013 - event slides
Cookies
Condor overview - glideinWMS Training Jan 2012
EdCamp News & UpDates
saic annual reports 2003
WebLion Hosting: Leveraging Laziness, Impatience, and Hubris
ITIL v3 story
Securing the e health cloud
The Django Book - Chapter 6 the django admin site
Uhy global directory-2013
For Self-Published Authors. Creative Content Opps. Bookexpo America uPublishU...
Ad

Recently uploaded (20)

PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Approach and Philosophy of On baking technology
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
Big Data Technologies - Introduction.pptx
PDF
Electronic commerce courselecture one. Pdf
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
cuic standard and advanced reporting.pdf
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPT
Teaching material agriculture food technology
Diabetes mellitus diagnosis method based random forest with bat algorithm
Unlocking AI with Model Context Protocol (MCP)
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Spectral efficient network and resource selection model in 5G networks
Approach and Philosophy of On baking technology
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Building Integrated photovoltaic BIPV_UPV.pdf
Dropbox Q2 2025 Financial Results & Investor Presentation
Advanced methodologies resolving dimensionality complications for autism neur...
Big Data Technologies - Introduction.pptx
Electronic commerce courselecture one. Pdf
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Per capita expenditure prediction using model stacking based on satellite ima...
cuic standard and advanced reporting.pdf
MYSQL Presentation for SQL database connectivity
Review of recent advances in non-invasive hemoglobin estimation
Network Security Unit 5.pdf for BCA BBA.
Digital-Transformation-Roadmap-for-Companies.pptx
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Teaching material agriculture food technology

RailsAdmin - Overview and Best practices

  • 1. RailsAdmin Overview & Best practices mercredi 7 août 13
  • 2. 14 years ago Acceptable in the 90’ mercredi 7 août 13
  • 3. Data Admin, stand-alone • + Pros • Reliable • Powerful • - Cons • No business rules whatsoever mercredi 7 août 13
  • 5. Data Admin, in the application • + Pros • Leverages the whole application or some parts for business rules etc. • - Cons • No direct (fast) DB administration • Your code? In theory... mercredi 7 août 13
  • 6. • Admin generator • Immediate startup • Steep learning curve • Extensible • Powerful when leverages Rails Models and Cancan • Admin builder • Slower startup • Simple DSL • Usable • Good for ad-hoc admin building when Models/Cancan rules don’t infer the UI RailsAdmin ActiveAdmin Grain of salt, common sense, etc. mercredi 7 août 13
  • 7. Pitfall • ActiveAdmin lets you do the work • => with some help from Formtastic :/ • RailsAdmin shortcuts ActiveModel • => Complex custom code laying on the ORMs :/ • But hey! it works®* ActiveModel does not provide anything for associations! * Unless you screwed up your models associations definitions mercredi 7 août 13
  • 8. Minimum installation • rails new new_app • rails g model blog::post title:string content:text • rails g model blog::comment content:text post:belongs_to • gem ‘rails_admin’ • mount RailsAdmin::Engine => ‘’ mercredi 7 août 13
  • 9. Big picture • Actions • Map routing to templates and controller • Sections • Map field configuration to each action • Fields • Handle fields configurations mercredi 7 août 13
  • 10. Actions-Sections CRUD mapping • new => new < edit < base • edit => update < edit < base • edit/new nested => nested < edit < base • edit/new modal => modal < edit < base • index => list < base • export => export < base mercredi 7 août 13
  • 12. The issue... • Never-ending list of section/fields definitions mercredi 7 août 13
  • 13. Solutions • Use configure as much as you can (doesn’t force the field list in opt-in mode) • Use order • Move each model configuration to a rails_admin block in class definition • Hide fields you don’t need instead of listing them (less overhead usually) mercredi 7 août 13
  • 15. The associations • has_many => nested • has_one => nested • belongs_to => modal • has_many :through => modal • has_and_belong_to_many => modal • It makes sense® mercredi 7 août 13
  • 16. Back to our models... mercredi 7 août 13
  • 17. You tell your ORM about it mercredi 7 août 13
  • 18. Stay on the Golden path • Convention over configuration! • RailsAdmin gets as much intel as it can from your models: • Fields • Associations • Validations • Don’t configure RailsAdmin when you can tweak your app to Rails’ best standards! mercredi 7 août 13
  • 19. But wait! Admin! Passwords and stuff! • gem ‘devise’ • rails g devise:install • rails g devise user • rails g migration add_user_id_to_blog_posts user:belongs_to • config/rails_admin.rb: mercredi 7 août 13
  • 20. Who am I? mercredi 7 août 13
  • 21. This is called authentication. Do you have authorization? • gem ‘cancan’ • rails g migration add_profile_to_users profile:string • config/rails_admin.rb: • rails g cancan:ability mercredi 7 août 13
  • 22. Some other profiles • Admin can do anything • Writer can • access rails_admin • access the dashboard • CRUD Blog::Post that he owns • for new posts, user_id will be forced to his id mercredi 7 août 13
  • 23. Ok, what do I get for my writers ? mercredi 7 août 13
  • 24. At last, some RailsAdmin field configuration! mercredi 7 août 13
  • 25. Deal with serialized fields • rails g migration add_metadata_to_blog_posts metadata:text • models/blog/post.rb mercredi 7 août 13
  • 26. Now what? • It’s error prone :( • It’s ugly :( • It’s not user friendly :( • It’s dangerous :( • What should I do? mercredi 7 août 13
  • 27. Use some ‘virtual’ fields? • You don’t need your object to respond to ‘block’ ! • You can create RailsAdmin fields out of the blue • You just need to define value and parse_input methods (in & out the form) • allowed_methods lets you modify the mass-assignable params on the object (safety) mercredi 7 août 13
  • 28. Say I need another one like ‘block’? • Let’s create a metadata RailsAdmin field type, in our application • lib/rails_admin/metadata.rb mercredi 7 août 13
  • 29. Time to leverage No pollution in the model! mercredi 7 août 13
  • 31. I need to publish my posts! Define an action, then use it mercredi 7 août 13
  • 32. Then the view part, simple stuff The view goes to rails_admin/ main/publish.slim Then add some translations for proper integration mercredi 7 août 13
  • 33. I’m in trouble • Check that your models are ok (rails c) • bundle open rails_admin • trace @abstract_model, @object in actions • trace @abstract_model, bindings[:object] in fields mercredi 7 août 13
  • 34. Someone said I need tests, I probably need tests, did I say I need tests? https://github.com/sferik/rails_admin/wiki/Rspec-with-capybara-examples mercredi 7 août 13
  • 35. Thanks for listening! Full example code https://github.com/bbenezech/blog_admin [email protected] @bbenezech github/Skype/twitter Freelance mercredi 7 août 13