Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
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
e...
cimon.io
companies_projects_issues_comments_path(
comment.issue.project.company,
comment.issue.project,
comment.issue,
com...
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, r...
cimon.io
Admin::UsersController
Client::ProfilesController
PublicApp::ProfilesController
link_to resource.name, [resource]...
cimon.io
Admin::UsersController
Client::ProfilesController
PublicApp::ProfilesController
link_to resource.name, [resource]...
cimon.io
Admin::ProjectsController
Client::MyProjectsController
PublicApp::ProjectsController
link_to resource.name, [reso...
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 :pr...
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, ...])
...
module Client
class ApplicationController
def url_for([..., User, ...] = resource)
url_for([..., resource.company, resourc...
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) {...
susanin({
[:client] => ->(_) { [:jericho] },
[User] => ->(r) { [r.company, r] },
[Project] => ->(r) { [:client, r] },
[Com...
susanin({
[:client] => ->(_) { [:jericho] },
[User] => ->(r) { [r.company, r] },
[Project] => ->(r) { [:client, r] },
[Com...
susanin({
[:client] => ->(_) { [:jericho] },
[User] => ->(r) { [r.company, r] },
[Project] => ->(r) { [:client, r] },
[Com...
susanin({
[User] => ->(r) { [:client, r] },
[:frontend, User] => ->(_, r) { [:public_app, r] },
})
[user] => [:client, use...
susanin({
[User] => ->(r) { [:client, r] },
[:frontend, User] => ->(_, r) { [:public_app, r] },
})
url_for([:frontend, use...
[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
Upcoming SlideShare
Loading in …5
×
Upcoming SlideShare
What to Upload to SlideShare
Next
Download to read offline and view in fullscreen.

0

Share

Download to read offline

Routes Generation. Susanin will Help! - Alexey Osipenko

Download to read offline

Ruby Meditation #15
May 13, 2017
Dnipro, I Coworking Hub

Related Books

Free with a 30 day trial from Scribd

See all

Related Audiobooks

Free with a 30 day trial from Scribd

See all
  • Be the first to like this

Routes Generation. Susanin will Help! - Alexey Osipenko

  1. 1. cimon.io Алексей Осипенко cimon.io «URL generation in Rails» Hello I’m Alexey
  2. 2. cimon.io Алексей Осипенко cimon.io «Susanin»
  3. 3. cimon.io Rails 5.1
  4. 4. cimon.io Rails 5.1 Direct Resolved routes &
  5. 5. cimon.io Rails 5.1 direct(:homepage) { "http://www.rubyonrails.org" }
  6. 6. cimon.io Rails 5.1 direct(:homepage) { "http://www.rubyonrails.org" } homepage_url()
  7. 7. cimon.io Rails 5.1 direct :commentable do |model|   [ model, anchor: model.dom_id ] end
  8. 8. cimon.io Rails 5.1 commentable_url(resource) direct :commentable do |model|   [ model, anchor: model.dom_id ] end
  9. 9. cimon.io What's the problem?
  10. 10. cimon.io resources :companies do resources :projects do resources :comments resources :issues do resources :comments end end end
  11. 11. cimon.io companies_projects_issues_comments_path( comment.issue.project.company, comment.issue.project, comment.issue, comment )
  12. 12. cimon.io comments_path(comment)
  13. 13. cimon.io url_for(comment)
  14. 14. cimon.io url_for([comment])
  15. 15. cimon.io everything is resource or collection
  16. 16. cimon.io everything is resource or collection or parent
  17. 17. cimon.io link_to(resource.name, [resource])
  18. 18. cimon.io Admin::UsersController Client::ProfilesController PublicApp::ProfilesController
  19. 19. 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]
  20. 20. cimon.io Admin::UsersController Client::ProfilesController PublicApp::ProfilesController link_to resource.name, [resource] link_to resource.name, [resource] link_to resource.name, [resource]
  21. 21. cimon.io Admin::UsersController Client::ProfilesController PublicApp::ProfilesController link_to resource.name, [resource] link_to resource.name, [resource] link_to resource.name, [resource] User
  22. 22. cimon.io Admin::ProjectsController Client::MyProjectsController PublicApp::ProjectsController link_to resource.name, [resource] link_to resource.name, [resource] link_to resource.name, [resource] Project
  23. 23. cimon.io url_for [:edit, :client, resource]
  24. 24. cimon.io url_for [:edit, resource]
  25. 25. cimon.io url_for [ :edit, :client, resource.project.company, resource.project, resource ]
  26. 26. namespace :client do resource :profiles end namespace :admin do resources :users end namespace :public_app do resource :profiles end
  27. 27. module Client class ApplicationController def url_for([User] = resource) super([:client, resource]) end end end
  28. 28. module Client class ApplicationController def users_url(resource) client_users_url(resource) end end end
  29. 29. module Client class ApplicationController def url_for([..., User, ...] = resource) url_for([..., :client, resource, ...]) end end end
  30. 30. 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
  31. 31. url_for([user]) url_for([:client, current_company, user])
  32. 32. cimon.io user company, user :client, company, user
  33. 33. module Client class ApplicationController susanin({ [User] => ->(user) { [user.company, user]}, [Company] => ->(company) { [:client, company] }, }) end end
  34. 34. susanin({ [:client] => ->(_) { [:jericho] }, [User] => ->(r) { [r.company, r] }, [Project] => ->(r) { [:client, r] }, [Company] => ->(r) { [:client, r] }, })
  35. 35. 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)
  36. 36. 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)
  37. 37. 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]
  38. 38. 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])
  39. 39. [A, B, C] => (a, b, c) { [1] } [A] => (a) { [2] } [A, B] => (a, b) { [3] } [a, b, c] => [1]
  40. 40. [A, B] => ->(a, b) { 1 } [A] => ->(a) { 2 } [A, B, C] => ->(a, b, c) { 3 } [a, b, c] => [1, c]
  41. 41. [A, B] => ->(a, b) { [a] } [A] => ->(a) { 2 } [A, B, C] => ->(a, b, c) { 3 } [a, b, c] => [2, c]
  42. 42. cimon.io
  43. 43. alexey@cimon.io Спасибо за внимание telegram@aratak alexey.osipenko@fb.me
  44. 44. https://t.me/itextrapolation

Ruby Meditation #15 May 13, 2017 Dnipro, I Coworking Hub

Views

Total views

422

On Slideshare

0

From embeds

0

Number of embeds

1

Actions

Downloads

0

Shares

0

Comments

0

Likes

0

×