Skip to content

Instantly share code, notes, and snippets.

View jdennes's full-sized avatar

James Dennes jdennes

View GitHub Profile
@jdennes
jdennes / recognize-path.md
Last active January 21, 2021 20:56
Easily get Rails controller and action from a route

Easily get Rails controller and action from a route:

irb(main):001:0> Rails.application.routes.recognize_path "/github/github/issues", method: "GET"
=> {:controller=>"issues", :action=>"index", :user_id=>"github", :repository=>"github"}
auth_options = {
bearer_token_file: "/var/run/secrets/kubernetes.io/serviceaccount/token"
}
ssl_options = {
ca_file: "/var/run/secrets/kubernetes.io/serviceaccount/ca.crt"
}
control_client = Kubeclient::Client.new \
"https://kubernetes.default.svc",
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>animation test</title>
<style>
body {
text-align: center;
font-family: 'Courier New', Courier, monospace;
}
@jdennes
jdennes / controller-and-action-from-path.md
Last active April 3, 2023 15:03
Get the Rails controller and action given a path

Get the Rails controller and action from a given path/route

Given an application path like /github/github/issues, use the following to get the controller and action:

irb(main):001:0> Rails.application.routes.recognize_path "/github/github/issues", method: "GET"
=> {:controller=>"issues", :action=>"index", :user_id=>"github", :repository=>"github"}

The /github/github/issues path maps to issues#index (the index action on the IssuesController).