SlideShare a Scribd company logo
1 of 35
Download to read offline
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

What's hot

Introduction To Single Page Application
Introduction To Single Page ApplicationIntroduction To Single Page Application
Introduction To Single Page Application
KMS Technology
 
[Final] ReactJS presentation
[Final] ReactJS presentation[Final] ReactJS presentation
[Final] ReactJS presentation
洪 鹏发
 
Best Practices NgRx for Scaling Your Angular Application
Best Practices NgRx  for Scaling Your Angular ApplicationBest Practices NgRx  for Scaling Your Angular Application
Best Practices NgRx for Scaling Your Angular Application
Vagner Oliveira
 
Introduction to hibernate
Introduction to hibernateIntroduction to hibernate
Introduction to hibernate
hr1383
 

What's hot (20)

Introduction into ES6 JavaScript.
Introduction into ES6 JavaScript.Introduction into ES6 JavaScript.
Introduction into ES6 JavaScript.
 
Mastering the Sling Rewriter
Mastering the Sling RewriterMastering the Sling Rewriter
Mastering the Sling Rewriter
 
React&redux
React&reduxReact&redux
React&redux
 
Javascript Prototype Visualized
Javascript Prototype VisualizedJavascript Prototype Visualized
Javascript Prototype Visualized
 
Introduction To Single Page Application
Introduction To Single Page ApplicationIntroduction To Single Page Application
Introduction To Single Page Application
 
Introduction to ReactJS
Introduction to ReactJSIntroduction to ReactJS
Introduction to ReactJS
 
AngularJS - Services
AngularJS - ServicesAngularJS - Services
AngularJS - Services
 
[Final] ReactJS presentation
[Final] ReactJS presentation[Final] ReactJS presentation
[Final] ReactJS presentation
 
Onion architecture
Onion architectureOnion architecture
Onion architecture
 
React for Beginners
React for BeginnersReact for Beginners
React for Beginners
 
Plack basics for Perl websites - YAPC::EU 2011
Plack basics for Perl websites - YAPC::EU 2011Plack basics for Perl websites - YAPC::EU 2011
Plack basics for Perl websites - YAPC::EU 2011
 
React js for beginners
React js for beginnersReact js for beginners
React js for beginners
 
React JS: A Secret Preview
React JS: A Secret PreviewReact JS: A Secret Preview
React JS: A Secret Preview
 
react redux.pdf
react redux.pdfreact redux.pdf
react redux.pdf
 
Best Practices NgRx for Scaling Your Angular Application
Best Practices NgRx  for Scaling Your Angular ApplicationBest Practices NgRx  for Scaling Your Angular Application
Best Practices NgRx for Scaling Your Angular Application
 
Introduction to hibernate
Introduction to hibernateIntroduction to hibernate
Introduction to hibernate
 
Laravel
LaravelLaravel
Laravel
 
ASP.NET MVC 5 - EF 6 - VS2015
ASP.NET MVC 5 - EF 6 - VS2015ASP.NET MVC 5 - EF 6 - VS2015
ASP.NET MVC 5 - EF 6 - VS2015
 
React.js 세미나
React.js 세미나React.js 세미나
React.js 세미나
 
Drools rule Concepts
Drools rule ConceptsDrools rule Concepts
Drools rule Concepts
 

Viewers also liked

Cookies
CookiesCookies
Cookies
epo273
 
EdCamp News & UpDates
EdCamp News & UpDatesEdCamp News & UpDates
EdCamp News & UpDates
Baker Publishing Company
 
saic annual reports 2003
saic annual reports 2003saic annual reports 2003
saic annual reports 2003
finance42
 

Viewers also liked (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...
 

Similar to RailsAdmin - Overview and Best practices

Intro to JavaScript Testing
Intro to JavaScript TestingIntro to JavaScript Testing
Intro to JavaScript Testing
Ran Mizrahi
 

Similar to 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
 

Recently uploaded

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Recently uploaded (20)

presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 

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