Skip to content

Instantly share code, notes, and snippets.

View siddhant3030's full-sized avatar
🎯
Focusing

Siddhant Singh siddhant3030

🎯
Focusing
View GitHub Profile
def routes
#...
@routes
end
if request_path =~ /^\articles$/
#go to articles#index
elsif request_path =~ /^\recipes$/
#go to recipes#index
elsif
# etc etc more looping ahh!
else
# route not found?
end
@routes || ActionDispatch::Routing::RouteSet.new
#action_dispatch/routing/route_set.rb
@set ||= Journey.Routes.new
Rails.application.routes.draw do
get '/login' => 'admin/sessions#new'
get '/logout' => 'admin/sessions#destroy'
namespace :admin do
resources :posts
resources :sessions, only: [:new, :create, :destroy]
resources :moderators, only: [:index, :edit, :update]
end
Prefix Verb URI Pattern Controller#Action
login GET /login(.:format) admin/sessions#new
logout GET /logout(.:format) admin/sessions#destroy
admin_posts GET /admin/posts(.:format) admin/posts#index
POST /admin/posts(.:format) admin/posts#create
new_admin_post GET /admin/posts/new(.:format) admin/posts#new
edit_admin_post GET /admin/posts/:id/edit(.:format) admin/posts#edit
admin_post GET /admin/posts/:id(.:format)
siddhants-MacBook-Air:railsblog sid$ rails c
Loading development environment (Rails 5.2.3)
irb(main):001:0> scanner = ActionDispatch::Journey::Scanner.new
=> #<ActionDispatch::Journey::Scanner:0x00007f84f432d658 @ss=nil>
irb(main):002:0> scanner.scan_setup("moderators/:id")
=> #<StringScanner 0/14 @ "moder...">
irb(main):003:0> scanner.next_token
=> [:LITERAL, "moderators"]
irb(main):004:0> scanner.next_token
=> [:SLASH, "/"]
siddhants-MacBook-Air:railsblog sid$ rails c
Loading development environment (Rails 5.2.3)
irb(main):001:0> parser = ActionDispatch::Journey::Parser.new
=> #<ActionDispatch::Journey::Parser:0x00007fa630dce528 @scanner=#<ActionDispatch::Journey::Scanner:0x00007fa630dce4b0 @ss=nil>>
irb(main):002:0> syntax_tree = parser.parse("/moderators/:id(.:format)")
=> #<ActionDispatch::Journey::Nodes::Cat:0x00007fa633df05d0 @left=#<ActionDispatch::Journey::Nodes::Slash:0x00007fa633df1110 @left="/", @memo=nil>, @memo=nil, @right=#<ActionDispatch::Journey::Nodes::Cat:0x00007fa633df0648 @left=#<ActionDispatch::Journey::Nodes::Literal:0x00007fa633df0ff8 @left="moderators", @memo=nil>, @memo=nil, @right=#<ActionDispatch::Journey::Nodes::Cat:0x00007fa633df0698 @left=#<ActionDispatch::Journey::Nodes::Slash:0x00007fa633df0f08 @left="/", @memo=nil>, @memo=nil, @right=#<ActionDispatch::Journey::Nodes::Cat:0x00007fa633df06e8 @left=#<ActionDispatch::Journey::Nodes::Symbol:0x00007fa633df0cb0 @left=":id", @memo=nil, @regexp=/[^\.\/\?]+
{[200, {}, [“Hello World”]]}
mix new dailyploy_project --umbrella
|-- apps
|-- config
| -config.exs
|-- mix.exs
|- README.md