snipt

Ctrl+h for KB shortcuts

Ruby irb session

List all routes for a Rails app

1
2
3
4
5
6
# Concise method
puts ActionController::Routing::Routes.routes

# Expanded method
rts = ActionController::Routing::Routes
puts rts.routes
https://snippets.siftie.com/embed/8b7de54f1e478564b69cdb56da54f965/
/raw/8b7de54f1e478564b69cdb56da54f965/
8b7de54f1e478564b69cdb56da54f965
rbcon
Ruby irb session
6
2019-03-15T00:31:04
True
False
False
/api/public/snipt/29766/
list-all-routes-for-a-rails-app
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="go"># Concise method</span> </span><span id="L-2"><a name="L-2"></a><span class="go">puts ActionController::Routing::Routes.routes</span> </span><span id="L-3"><a name="L-3"></a> </span><span id="L-4"><a name="L-4"></a><span class="go"># Expanded method</span> </span><span id="L-5"><a name="L-5"></a><span class="go">rts = ActionController::Routing::Routes</span> </span><span id="L-6"><a name="L-6"></a><span class="go">puts rts.routes</span> </span></pre></div> </td></tr></table>
information, rails, routes, ruby

Ruby

to allow this route: /users/mr.chawei

1
2
3
# config/routes.rb
map.resources :users,
  :requirements => { :id => %r([^/;,?]+) }
https://snippets.siftie.com/embed/d64dc968190cf611bbc4487b25c7b8c4/
/raw/d64dc968190cf611bbc4487b25c7b8c4/
d64dc968190cf611bbc4487b25c7b8c4
rb
Ruby
3
2019-03-07T10:29:06
True
False
False
/api/public/snipt/1865/
to-allow-this-route-usersmrchawei
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="c1"># config/routes.rb</span> </span><span id="L-2"><a name="L-2"></a><span class="n">map</span><span class="o">.</span><span class="n">resources</span> <span class="ss">:users</span><span class="p">,</span> </span><span id="L-3"><a name="L-3"></a> <span class="ss">:requirements</span> <span class="o">=&gt;</span> <span class="p">{</span> <span class="ss">:id</span> <span class="o">=&gt;</span> <span class="sr">%r([^/;,?]+)</span> <span class="p">}</span> </span></pre></div> </td></tr></table>
rails, routes