SlideShare une entreprise Scribd logo
1  sur  35
Télécharger pour lire hors ligne
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

Contenu connexe

Tendances

Angular - Chapter 7 - HTTP Services
Angular - Chapter 7 - HTTP ServicesAngular - Chapter 7 - HTTP Services
Angular - Chapter 7 - HTTP ServicesWebStackAcademy
 
PyCon Korea 2019 REST API Document Generation
PyCon Korea 2019 REST API Document GenerationPyCon Korea 2019 REST API Document Generation
PyCon Korea 2019 REST API Document Generation용선 이
 
REST APIs with Spring
REST APIs with SpringREST APIs with Spring
REST APIs with SpringJoshua Long
 
Angular 4 The new Http Client Module
Angular 4 The new Http Client ModuleAngular 4 The new Http Client Module
Angular 4 The new Http Client Modulearjun singh
 
Celery: The Distributed Task Queue
Celery: The Distributed Task QueueCelery: The Distributed Task Queue
Celery: The Distributed Task QueueRichard Leland
 
Spring boot introduction
Spring boot introductionSpring boot introduction
Spring boot introductionRasheed Waraich
 
Angular Dependency Injection
Angular Dependency InjectionAngular Dependency Injection
Angular Dependency InjectionNir Kaufman
 
Spring boot Introduction
Spring boot IntroductionSpring boot Introduction
Spring boot IntroductionJeevesh Pandey
 
Spring boot
Spring bootSpring boot
Spring bootsdeeg
 
VueJS Introduction
VueJS IntroductionVueJS Introduction
VueJS IntroductionDavid Ličen
 
Whitebox testing of Spring Boot applications
Whitebox testing of Spring Boot applicationsWhitebox testing of Spring Boot applications
Whitebox testing of Spring Boot applicationsYura Nosenko
 
Nestjs MasterClass Slides
Nestjs MasterClass SlidesNestjs MasterClass Slides
Nestjs MasterClass SlidesNir Kaufman
 
Europython 2011 - Playing tasks with Django & Celery
Europython 2011 - Playing tasks with Django & CeleryEuropython 2011 - Playing tasks with Django & Celery
Europython 2011 - Playing tasks with Django & CeleryMauro Rocco
 

Tendances (20)

Angular - Chapter 7 - HTTP Services
Angular - Chapter 7 - HTTP ServicesAngular - Chapter 7 - HTTP Services
Angular - Chapter 7 - HTTP Services
 
PyCon Korea 2019 REST API Document Generation
PyCon Korea 2019 REST API Document GenerationPyCon Korea 2019 REST API Document Generation
PyCon Korea 2019 REST API Document Generation
 
REST APIs with Spring
REST APIs with SpringREST APIs with Spring
REST APIs with Spring
 
React js
React jsReact js
React js
 
Angular 4 The new Http Client Module
Angular 4 The new Http Client ModuleAngular 4 The new Http Client Module
Angular 4 The new Http Client Module
 
Celery: The Distributed Task Queue
Celery: The Distributed Task QueueCelery: The Distributed Task Queue
Celery: The Distributed Task Queue
 
Laravel Eloquent ORM
Laravel Eloquent ORMLaravel Eloquent ORM
Laravel Eloquent ORM
 
React JS
React JSReact JS
React JS
 
Spring boot introduction
Spring boot introductionSpring boot introduction
Spring boot introduction
 
Angular Dependency Injection
Angular Dependency InjectionAngular Dependency Injection
Angular Dependency Injection
 
NestJS
NestJSNestJS
NestJS
 
Spring boot Introduction
Spring boot IntroductionSpring boot Introduction
Spring boot Introduction
 
Spring boot
Spring bootSpring boot
Spring boot
 
Gradle Introduction
Gradle IntroductionGradle Introduction
Gradle Introduction
 
VueJS Introduction
VueJS IntroductionVueJS Introduction
VueJS Introduction
 
Whitebox testing of Spring Boot applications
Whitebox testing of Spring Boot applicationsWhitebox testing of Spring Boot applications
Whitebox testing of Spring Boot applications
 
How to Design Indexes, Really
How to Design Indexes, ReallyHow to Design Indexes, Really
How to Design Indexes, Really
 
Nestjs MasterClass Slides
Nestjs MasterClass SlidesNestjs MasterClass Slides
Nestjs MasterClass Slides
 
Europython 2011 - Playing tasks with Django & Celery
Europython 2011 - Playing tasks with Django & CeleryEuropython 2011 - Playing tasks with Django & Celery
Europython 2011 - Playing tasks with Django & Celery
 
Angular Data Binding
Angular Data BindingAngular Data Binding
Angular Data Binding
 

En vedette

RailsAdmin - the right way of doing data administration with Rails 3
RailsAdmin - the right way of doing data administration with Rails 3RailsAdmin - the right way of doing data administration with Rails 3
RailsAdmin - the right way of doing data administration with Rails 3Bogdan Gaza
 
Rails Admin - Guru SP
Rails Admin - Guru SPRails Admin - Guru SP
Rails Admin - Guru SPFabio Akita
 
Calendário de abastecimento - março (alterado)
Calendário de abastecimento - março (alterado)Calendário de abastecimento - março (alterado)
Calendário de abastecimento - março (alterado)Portal NE10
 
軽い! 速い! サーバを選ばない! Ruby製CMS "nanoc"
軽い! 速い! サーバを選ばない! Ruby製CMS "nanoc"軽い! 速い! サーバを選ばない! Ruby製CMS "nanoc"
軽い! 速い! サーバを選ばない! Ruby製CMS "nanoc"Go Maeda
 
SF1 - Apex Development Best Practises
SF1 - Apex Development Best PractisesSF1 - Apex Development Best Practises
SF1 - Apex Development Best PractisesSebastian Wagner
 
Globo.com - migração do player flash para html5
Globo.com  - migração do player flash para html5Globo.com  - migração do player flash para html5
Globo.com - migração do player flash para html5Leandro Moreira
 
Amazon S3とnanocで作る 安い・落ちないwebサイト
Amazon S3とnanocで作る 安い・落ちないwebサイトAmazon S3とnanocで作る 安い・落ちないwebサイト
Amazon S3とnanocで作る 安い・落ちないwebサイトGo Maeda
 
Weblogic Server
Weblogic ServerWeblogic Server
Weblogic Serveracsvianabr
 
Be2Awards and Be2Talks 2013 - event slides
Be2Awards and Be2Talks 2013 - event slidesBe2Awards and Be2Talks 2013 - event slides
Be2Awards and Be2Talks 2013 - event slidesBe2camp Admin
 
Cookies
CookiesCookies
Cookiesepo273
 
Condor overview - glideinWMS Training Jan 2012
Condor overview - glideinWMS Training Jan 2012Condor overview - glideinWMS Training Jan 2012
Condor overview - glideinWMS Training Jan 2012Igor Sfiligoi
 
saic annual reports 2003
saic annual reports 2003saic annual reports 2003
saic annual reports 2003finance42
 
WebLion Hosting: Leveraging Laziness, Impatience, and Hubris
WebLion Hosting: Leveraging Laziness, Impatience, and HubrisWebLion Hosting: Leveraging Laziness, Impatience, and Hubris
WebLion Hosting: Leveraging Laziness, Impatience, and HubrisErik Rose
 
Securing the e health cloud
Securing the e health cloudSecuring the e health cloud
Securing the e health cloudBong Young Sung
 
The Django Book - Chapter 6 the django admin site
The Django Book - Chapter 6  the django admin siteThe Django Book - Chapter 6  the django admin site
The Django Book - Chapter 6 the django admin siteVincent Chien
 
Uhy global directory-2013
Uhy global directory-2013Uhy global directory-2013
Uhy global directory-2013Dawgen Global
 
For Self-Published Authors. Creative Content Opps. Bookexpo America uPublishU...
For Self-Published Authors. Creative Content Opps. Bookexpo America uPublishU...For Self-Published Authors. Creative Content Opps. Bookexpo America uPublishU...
For Self-Published Authors. Creative Content Opps. Bookexpo America uPublishU...Susannah Greenberg
 

En vedette (20)

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

Similaire à RailsAdmin - Overview and Best practices

jQuery Mobile Deep Dive
jQuery Mobile Deep DivejQuery Mobile Deep Dive
jQuery Mobile Deep DiveTroy Miles
 
When Sightly Meets Slice by Tomasz Niedźwiedź
When Sightly Meets Slice by Tomasz NiedźwiedźWhen Sightly Meets Slice by Tomasz Niedźwiedź
When Sightly Meets Slice by Tomasz NiedźwiedźAEM HUB
 
Performant Django - Ara Anjargolian
Performant Django - Ara AnjargolianPerformant Django - Ara Anjargolian
Performant Django - Ara AnjargolianHakka Labs
 
Tek 2013 - Building Web Apps from a New Angle with AngularJS
Tek 2013 - Building Web Apps from a New Angle with AngularJSTek 2013 - Building Web Apps from a New Angle with AngularJS
Tek 2013 - Building Web Apps from a New Angle with AngularJSPablo Godel
 
Introduction to Sightly and Sling Models
Introduction to Sightly and Sling ModelsIntroduction to Sightly and Sling Models
Introduction to Sightly and Sling ModelsStefano Celentano
 
ITARC15 Workshop - Architecting a Large Software Project - Lessons Learned
ITARC15 Workshop - Architecting a Large Software Project - Lessons LearnedITARC15 Workshop - Architecting a Large Software Project - Lessons Learned
ITARC15 Workshop - Architecting a Large Software Project - Lessons LearnedJoão Pedro Martins
 
Rails Tips and Best Practices
Rails Tips and Best PracticesRails Tips and Best Practices
Rails Tips and Best PracticesDavid Keener
 
How You Convince Your Manager To Adopt Scala.js in Production
How You Convince Your Manager To Adopt Scala.js in ProductionHow You Convince Your Manager To Adopt Scala.js in Production
How You Convince Your Manager To Adopt Scala.js in ProductionBoldRadius Solutions
 
How to build a PostgreSQL-backed website quickly
How to build a PostgreSQL-backed website quicklyHow to build a PostgreSQL-backed website quickly
How to build a PostgreSQL-backed website quicklyJohn Ashmead
 
Using Rails to Create an Enterprise App: A Real-Life Case Study
Using Rails to Create an Enterprise App: A Real-Life Case StudyUsing Rails to Create an Enterprise App: A Real-Life Case Study
Using Rails to Create an Enterprise App: A Real-Life Case StudyDavid Keener
 
Rspec and Capybara Intro Tutorial at RailsConf 2013
Rspec and Capybara Intro Tutorial at RailsConf 2013Rspec and Capybara Intro Tutorial at RailsConf 2013
Rspec and Capybara Intro Tutorial at RailsConf 2013Brian Sam-Bodden
 
Automated perf optimization - jQuery Conference
Automated perf optimization - jQuery ConferenceAutomated perf optimization - jQuery Conference
Automated perf optimization - jQuery ConferenceMatthew Lancaster
 
From Renamer Plugin to Polyglot IDE
From Renamer Plugin to Polyglot IDEFrom Renamer Plugin to Polyglot IDE
From Renamer Plugin to Polyglot IDEintelliyole
 
Intro to JavaScript Testing
Intro to JavaScript TestingIntro to JavaScript Testing
Intro to JavaScript TestingRan Mizrahi
 
SPSDenver - SharePoint & jQuery - What I wish I would have known
SPSDenver - SharePoint & jQuery - What I wish I would have knownSPSDenver - SharePoint & jQuery - What I wish I would have known
SPSDenver - SharePoint & jQuery - What I wish I would have knownMark Rackley
 

Similaire à RailsAdmin - Overview and Best practices (20)

jQuery Mobile Deep Dive
jQuery Mobile Deep DivejQuery Mobile Deep Dive
jQuery Mobile Deep Dive
 
Qcon talk
Qcon talkQcon talk
Qcon talk
 
When Sightly Meets Slice by Tomasz Niedźwiedź
When Sightly Meets Slice by Tomasz NiedźwiedźWhen Sightly Meets Slice by Tomasz Niedźwiedź
When Sightly Meets Slice by Tomasz Niedźwiedź
 
Performant Django - Ara Anjargolian
Performant Django - Ara AnjargolianPerformant Django - Ara Anjargolian
Performant Django - Ara Anjargolian
 
Tek 2013 - Building Web Apps from a New Angle with AngularJS
Tek 2013 - Building Web Apps from a New Angle with AngularJSTek 2013 - Building Web Apps from a New Angle with AngularJS
Tek 2013 - Building Web Apps from a New Angle with AngularJS
 
Introduction to Sightly and Sling Models
Introduction to Sightly and Sling ModelsIntroduction to Sightly and Sling Models
Introduction to Sightly and Sling Models
 
Introduction to AngularJs
Introduction to AngularJsIntroduction to AngularJs
Introduction to AngularJs
 
ITARC15 Workshop - Architecting a Large Software Project - Lessons Learned
ITARC15 Workshop - Architecting a Large Software Project - Lessons LearnedITARC15 Workshop - Architecting a Large Software Project - Lessons Learned
ITARC15 Workshop - Architecting a Large Software Project - Lessons Learned
 
Rails Tips and Best Practices
Rails Tips and Best PracticesRails Tips and Best Practices
Rails Tips and Best Practices
 
Backbone
BackboneBackbone
Backbone
 
How You Convince Your Manager To Adopt Scala.js in Production
How You Convince Your Manager To Adopt Scala.js in ProductionHow You Convince Your Manager To Adopt Scala.js in Production
How You Convince Your Manager To Adopt Scala.js in Production
 
How to build a PostgreSQL-backed website quickly
How to build a PostgreSQL-backed website quicklyHow to build a PostgreSQL-backed website quickly
How to build a PostgreSQL-backed website quickly
 
Gradle Again
Gradle AgainGradle Again
Gradle Again
 
Using Rails to Create an Enterprise App: A Real-Life Case Study
Using Rails to Create an Enterprise App: A Real-Life Case StudyUsing Rails to Create an Enterprise App: A Real-Life Case Study
Using Rails to Create an Enterprise App: A Real-Life Case Study
 
Breaking data
Breaking dataBreaking data
Breaking data
 
Rspec and Capybara Intro Tutorial at RailsConf 2013
Rspec and Capybara Intro Tutorial at RailsConf 2013Rspec and Capybara Intro Tutorial at RailsConf 2013
Rspec and Capybara Intro Tutorial at RailsConf 2013
 
Automated perf optimization - jQuery Conference
Automated perf optimization - jQuery ConferenceAutomated perf optimization - jQuery Conference
Automated perf optimization - jQuery Conference
 
From Renamer Plugin to Polyglot IDE
From Renamer Plugin to Polyglot IDEFrom Renamer Plugin to Polyglot IDE
From Renamer Plugin to Polyglot IDE
 
Intro to JavaScript Testing
Intro to JavaScript TestingIntro to JavaScript Testing
Intro to JavaScript Testing
 
SPSDenver - SharePoint & jQuery - What I wish I would have known
SPSDenver - SharePoint & jQuery - What I wish I would have knownSPSDenver - SharePoint & jQuery - What I wish I would have known
SPSDenver - SharePoint & jQuery - What I wish I would have known
 

Dernier

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfOverkill Security
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024The Digital Insurer
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 

Dernier (20)

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 

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 benoit.benezech@gmail.com @bbenezech github/Skype/twitter Freelance mercredi 7 août 13