SlideShare a Scribd company logo
cimon.io
Алексей Осипенко
cimon.io
«URL generation in Rails»
Hello I’m
Alexey
cimon.io
Алексей Осипенко
cimon.io
«Susanin»
cimon.io
Rails 5.1
cimon.io
Rails 5.1
Direct
Resolved routes
&
cimon.io
Rails 5.1
direct(:homepage) {
"http://www.rubyonrails.org"
}
cimon.io
Rails 5.1
direct(:homepage) {
"http://www.rubyonrails.org"
}
homepage_url()
cimon.io
Rails 5.1
direct :commentable do |model|
  [ model, anchor: model.dom_id ]
end
cimon.io
Rails 5.1
commentable_url(resource)
direct :commentable do |model|
  [ model, anchor: model.dom_id ]
end
cimon.io
What's the problem?
cimon.io
resources :companies do
resources :projects do
resources :comments
resources :issues do
resources :comments
end
end
end
cimon.io
companies_projects_issues_comments_path(
comment.issue.project.company,
comment.issue.project,
comment.issue,
comment
)
cimon.io
comments_path(comment)
cimon.io
url_for(comment)
cimon.io
url_for([comment])
cimon.io
everything is
resource
or
collection
cimon.io
everything is
resource
or
collection
or
parent
cimon.io
link_to(resource.name, [resource])
cimon.io
Admin::UsersController
Client::ProfilesController
PublicApp::ProfilesController
cimon.io
Admin::UsersController
Client::ProfilesController
PublicApp::ProfilesController
link_to resource.name, [:admin, resource]
link_to resource.name, [:client, resource]
link_to resource.name, [:public, resource]
cimon.io
Admin::UsersController
Client::ProfilesController
PublicApp::ProfilesController
link_to resource.name, [resource]
link_to resource.name, [resource]
link_to resource.name, [resource]
cimon.io
Admin::UsersController
Client::ProfilesController
PublicApp::ProfilesController
link_to resource.name, [resource]
link_to resource.name, [resource]
link_to resource.name, [resource]
User
cimon.io
Admin::ProjectsController
Client::MyProjectsController
PublicApp::ProjectsController
link_to resource.name, [resource]
link_to resource.name, [resource]
link_to resource.name, [resource]
Project
cimon.io
url_for [:edit, :client, resource]
cimon.io
url_for [:edit, resource]
cimon.io
url_for [
:edit,
:client,
resource.project.company,
resource.project,
resource
]
namespace :client do
resource :profiles
end
namespace :admin do
resources :users
end
namespace :public_app do
resource :profiles
end
module Client
class ApplicationController
def url_for([User] = resource)
super([:client, resource])
end
end
end
module Client
class ApplicationController
def users_url(resource)
client_users_url(resource)
end
end
end
module Client
class ApplicationController
def url_for([..., User, ...] = resource)
url_for([..., :client, resource, ...])
end
end
end
module Client
class ApplicationController
def url_for([..., User, ...] = resource)
url_for([..., resource.company, resource, ...])
end
def url_for([..., Company, ...])
url_for([:client, current_company])
end
end
end
url_for([user])
url_for([:client, current_company, user])
cimon.io
user company, user :client, company, user
module Client
class ApplicationController
susanin({
[User] => ->(user) { [user.company, user]},
[Company] => ->(company) { [:client, company] },
})
end
end
susanin({
[:client] => ->(_) { [:jericho] },
[User] => ->(r) { [r.company, r] },
[Project] => ->(r) { [:client, r] },
[Company] => ->(r) { [:client, r] },
})
susanin({
[:client] => ->(_) { [:jericho] },
[User] => ->(r) { [r.company, r] },
[Project] => ->(r) { [:client, r] },
[Company] => ->(r) { [:client, r] },
})
url_for([user])
url_for([:jericho, company, user])
jericho_company_user_url(company, user)
susanin({
[:client] => ->(_) { [:jericho] },
[User] => ->(r) { [r.company, r] },
[Project] => ->(r) { [:client, r] },
[Company] => ->(r) { [:client, r] },
})
url_for([:edit, user])
url_for([:edit, company, user])
url_for([:edit, :client, company, user])
url_for([:edit, :jericho, company, user])
edit_jericho_company_user_url(company, user)
susanin({
[User] => ->(r) { [:client, r] },
[:frontend, User] => ->(_, r) { [:public_app, r] },
})
[user] => [:client, user]
[:frontend, user] => [:public_app, user]
[:edit, user] => [:edit, :client, user]
[:edit, :frontend, user] => [:edit, :public_app, user]
susanin({
[User] => ->(r) { [:client, r] },
[:frontend, User] => ->(_, r) { [:public_app, r] },
})
url_for([:frontend, user])
url_for([:client, :frontend, user])
url_for([:public_app, user])
[A, B, C] => (a, b, c) { [1] }
[A] => (a) { [2] }
[A, B] => (a, b) { [3] }
[a, b, c] => [1]
[A, B] => ->(a, b) { 1 }
[A] => ->(a) { 2 }
[A, B, C] => ->(a, b, c) { 3 }
[a, b, c] => [1, c]
[A, B] => ->(a, b) { [a] }
[A] => ->(a) { 2 }
[A, B, C] => ->(a, b, c) { 3 }
[a, b, c] => [2, c]
cimon.io
alexey@cimon.io
Спасибо
за
внимание
telegram@aratak
alexey.osipenko@fb.me
https://t.me/itextrapolation

More Related Content

KEY
Vim Text Object
PDF
"Full Stack frameworks or a story about how to reconcile Front (good) and Bac...
PPTX
d.mix: Programming by a Sample
PDF
Introduction to Django
PDF
Django introduction
PPTX
Python Code Camp for Professionals 3/4
PDF
Adopting F# at SBTech
PDF
Road to Rails
Vim Text Object
"Full Stack frameworks or a story about how to reconcile Front (good) and Bac...
d.mix: Programming by a Sample
Introduction to Django
Django introduction
Python Code Camp for Professionals 3/4
Adopting F# at SBTech
Road to Rails

Similar to Routes Generation. Susanin will Help! - Alexey Osipenko (20)

PDF
The Best (and Worst) of Django
PDF
Modern Release Engineering in a Nutshell - Why Researchers should Care!
ODP
Pyramid Lighter/Faster/Better web apps
PDF
Rails for Beginners - Le Wagon
PDF
KEY
Socket applications
PDF
Паразитируем на React-экосистеме (Angular 4+) / Алексей Охрименко (IPONWEB)
PDF
Mashing Up The Guardian
PDF
Mashing Up The Guardian
PPTX
Golang slidesaudrey
PDF
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)
PDF
Keeping the frontend under control with Symfony and Webpack
PPT
JBUG 11 - Django-The Web Framework For Perfectionists With Deadlines
PDF
OSCamp #4 on Foreman | CLI tools with Foreman by Martin Bačovský
PPTX
Exploring the Titanium CLI - Codestrong 2012
PDF
Building a Single Page Application using Ember.js ... for fun and profit
PDF
Connecting your Python App to OpenERP through OOOP
PDF
Rails::Engine
PDF
Introduction to React Native Workshop
PDF
How To Structure Go Applications - Paul Bellamy - Codemotion Milan 2016
The Best (and Worst) of Django
Modern Release Engineering in a Nutshell - Why Researchers should Care!
Pyramid Lighter/Faster/Better web apps
Rails for Beginners - Le Wagon
Socket applications
Паразитируем на React-экосистеме (Angular 4+) / Алексей Охрименко (IPONWEB)
Mashing Up The Guardian
Mashing Up The Guardian
Golang slidesaudrey
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)
Keeping the frontend under control with Symfony and Webpack
JBUG 11 - Django-The Web Framework For Perfectionists With Deadlines
OSCamp #4 on Foreman | CLI tools with Foreman by Martin Bačovský
Exploring the Titanium CLI - Codestrong 2012
Building a Single Page Application using Ember.js ... for fun and profit
Connecting your Python App to OpenERP through OOOP
Rails::Engine
Introduction to React Native Workshop
How To Structure Go Applications - Paul Bellamy - Codemotion Milan 2016
Ad

More from Ruby Meditation (20)

PDF
Is this Legacy or Revenant Code? - Sergey Sergyenko | Ruby Meditation 30
PDF
Life with GraphQL API: good practices and unresolved issues - Roman Dubrovsky...
PDF
Where is your license, dude? - Viacheslav Miroshnychenko | Ruby Meditation 29
PDF
Dry-validation update. Dry-validation vs Dry-schema 1.0 - Aleksandra Stolyar ...
PDF
How to cook Rabbit on Production - Bohdan Parshentsev | Ruby Meditation 28
PDF
How to cook Rabbit on Production - Serhiy Nazarov | Ruby Meditation 28
PDF
Reinventing the wheel - why do it and how to feel good about it - Julik Tarkh...
PDF
Performance Optimization 101 for Ruby developers - Nihad Abbasov (ENG) | Ruby...
PDF
Use cases for Serverless Technologies - Ruslan Tolstov (RUS) | Ruby Meditatio...
PDF
The Trailblazer Ride from the If Jungle into a Civilised Railway Station - Or...
PDF
What/How to do with GraphQL? - Valentyn Ostakh (ENG) | Ruby Meditation 27
PDF
New features in Rails 6 - Nihad Abbasov (RUS) | Ruby Meditation 26
PDF
Security Scanning Overview - Tetiana Chupryna (RUS) | Ruby Meditation 26
PDF
Teach your application eloquence. Logs, metrics, traces - Dmytro Shapovalov (...
PDF
Best practices. Exploring - Ike Kurghinyan (RUS) | Ruby Meditation 26
PDF
Road to A/B testing - Alexey Vasiliev (ENG) | Ruby Meditation 25
PDF
Concurrency in production. Real life example - Dmytro Herasymuk | Ruby Medita...
PDF
Data encryption for Ruby web applications - Dmytro Shapovalov (RUS) | Ruby Me...
PDF
Rails App performance at the limit - Bogdan Gusiev
PDF
GDPR. Next Y2K in 2018? - Anton Tkachov | Ruby Meditation #23
Is this Legacy or Revenant Code? - Sergey Sergyenko | Ruby Meditation 30
Life with GraphQL API: good practices and unresolved issues - Roman Dubrovsky...
Where is your license, dude? - Viacheslav Miroshnychenko | Ruby Meditation 29
Dry-validation update. Dry-validation vs Dry-schema 1.0 - Aleksandra Stolyar ...
How to cook Rabbit on Production - Bohdan Parshentsev | Ruby Meditation 28
How to cook Rabbit on Production - Serhiy Nazarov | Ruby Meditation 28
Reinventing the wheel - why do it and how to feel good about it - Julik Tarkh...
Performance Optimization 101 for Ruby developers - Nihad Abbasov (ENG) | Ruby...
Use cases for Serverless Technologies - Ruslan Tolstov (RUS) | Ruby Meditatio...
The Trailblazer Ride from the If Jungle into a Civilised Railway Station - Or...
What/How to do with GraphQL? - Valentyn Ostakh (ENG) | Ruby Meditation 27
New features in Rails 6 - Nihad Abbasov (RUS) | Ruby Meditation 26
Security Scanning Overview - Tetiana Chupryna (RUS) | Ruby Meditation 26
Teach your application eloquence. Logs, metrics, traces - Dmytro Shapovalov (...
Best practices. Exploring - Ike Kurghinyan (RUS) | Ruby Meditation 26
Road to A/B testing - Alexey Vasiliev (ENG) | Ruby Meditation 25
Concurrency in production. Real life example - Dmytro Herasymuk | Ruby Medita...
Data encryption for Ruby web applications - Dmytro Shapovalov (RUS) | Ruby Me...
Rails App performance at the limit - Bogdan Gusiev
GDPR. Next Y2K in 2018? - Anton Tkachov | Ruby Meditation #23
Ad

Recently uploaded (20)

PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Empathic Computing: Creating Shared Understanding
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
Big Data Technologies - Introduction.pptx
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
A Presentation on Artificial Intelligence
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Understanding_Digital_Forensics_Presentation.pptx
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Reach Out and Touch Someone: Haptics and Empathic Computing
NewMind AI Weekly Chronicles - August'25 Week I
Review of recent advances in non-invasive hemoglobin estimation
20250228 LYD VKU AI Blended-Learning.pptx
Empathic Computing: Creating Shared Understanding
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Big Data Technologies - Introduction.pptx
NewMind AI Monthly Chronicles - July 2025
The Rise and Fall of 3GPP – Time for a Sabbatical?
A Presentation on Artificial Intelligence
“AI and Expert System Decision Support & Business Intelligence Systems”
Unlocking AI with Model Context Protocol (MCP)
Per capita expenditure prediction using model stacking based on satellite ima...
Building Integrated photovoltaic BIPV_UPV.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
Build a system with the filesystem maintained by OSTree @ COSCUP 2025

Routes Generation. Susanin will Help! - Alexey Osipenko