Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In Browser Path Matching with Javascript #9001

Merged
merged 1 commit into from Jan 21, 2013

Conversation

@schneems
Copy link
Member

commented Jan 19, 2013

When debugging routes it can sometimes be difficult to understand exactly how the paths are matched. This PR adds a JS based path matching widget to the /rails/info/routes output. You can enter in a path, and it will tell you which of the routes that path matches, while preserving order (top match wins).

The matching widget in action:

Prior to this PR the only way to check matching paths is via mental math, or typing in a path in the url bar and seeing where it goes. This feature will be an invaluable debugging tool by dramatically decreasing the time needed to check a path match.

To newcomers: you can run this route page in Rails 3.2 (without this feature), using Sextant.

It has also been noted that this PR is: OVER 9000.

ATP actionpack

@mdespuits

This comment has been minimized.

Copy link
Contributor

commented Jan 19, 2013

Wow. Just Wow. 👍

@Jauny

This comment has been minimized.

Copy link

commented Jan 19, 2013

yea just wow, amazing 👍

@Antiarchitect

This comment has been minimized.

Copy link
Contributor

commented Jan 19, 2013

Like! 👍

@frodsan

This comment has been minimized.

Copy link
Contributor

commented Jan 19, 2013

Awesome 👍

@MadRabbit

This comment has been minimized.

Copy link

commented Jan 19, 2013

$ rails routes | grep foo

but generally looks like fun :)

@h3h

This comment has been minimized.

Copy link

commented Jan 19, 2013

👍

@h3h

View changes

actionpack/lib/action_dispatch/middleware/templates/routes/_table.html.erb Outdated
}

// Ensure path always starts with a slash "/" and remove params or fragments
function sanatizePath(path) {

This comment has been minimized.

Copy link
@h3h

h3h Jan 19, 2013

sanitizePath for the greater spelling win. 😄

@goshakkk

This comment has been minimized.

Copy link
Contributor

commented Jan 19, 2013

👍

@Jacke

This comment has been minimized.

Copy link

commented Jan 19, 2013

👍 Awesome!!

@drnic

This comment has been minimized.

Copy link
Contributor

commented Jan 19, 2013

A very appropriate PR for #9001!

@aviflombaum

This comment has been minimized.

Copy link

commented Jan 19, 2013

dude, killer. 👍 its like better_errors for routes :-)

@jrgifford

This comment has been minimized.

Copy link
Contributor

commented Jan 19, 2013

does this work in production? That's the only question I have. (i will admit i haven't looked at the code for this.)

@schneems

This comment has been minimized.

Copy link
Member Author

commented Jan 19, 2013

@jrgifford you cannot access this url in production, it is in an internal controller only added in development, and there is a before filter that will prevent anyone from accessing this page unless it is a local request.

@shedd

This comment has been minimized.

Copy link

commented Jan 19, 2013

Fantastic idea!

@hankblinq

This comment has been minimized.

Copy link

commented Jan 19, 2013

Clap Clap Clap!

@jrgifford

This comment has been minimized.

Copy link
Contributor

commented Jan 19, 2013

@schneems ah, ok. excellent!

@mmay

This comment has been minimized.

Copy link

commented Jan 20, 2013

👍

@thenickcox

This comment has been minimized.

Copy link
Contributor

commented Jan 20, 2013

Here's to hoping we use the ability to use animated GIFs in pull requests for good, not for annoying.

@codeblooded

This comment has been minimized.

Copy link

commented Jan 20, 2013

👍 Yeah!!!

@BMorearty

This comment has been minimized.

Copy link
Contributor

commented Jan 20, 2013

❤️

@jfairchild

This comment has been minimized.

Copy link

commented Jan 20, 2013

👍

@jgaskins

This comment has been minimized.

Copy link
Contributor

commented Jan 20, 2013

@drnic This PR is, indeed, over 9000.

@pacoguzman

This comment has been minimized.

Copy link
Contributor

commented Jan 20, 2013

🤘

@pixeltrix

View changes

actionpack/lib/action_dispatch/routing/inspector.rb Outdated
@route = route
super(@route)
end

This comment has been minimized.

Copy link
@pixeltrix

pixeltrix Jan 20, 2013

Member

I assume that you're capturing the route for the regex method below? If so can't we delete this method and implement regex like this:

def regex
  __get_object__.path.to_regexp
end

Also can we keep the names consistent - use regexp instead of regex.

This comment has been minimized.

Copy link
@carlosantoniodasilva

This comment has been minimized.

Copy link
@schneems

schneems Jan 20, 2013

Author Member

thanks, i had never worked with SimpleDelegator before, looks like it's __getobj__

@carlosantoniodasilva

View changes

actionpack/lib/action_dispatch/middleware/templates/routes/_table.html.erb Outdated
}

#route_table {
margin: 0 auto 0;

This comment has been minimized.

Copy link
@carlosantoniodasilva

carlosantoniodasilva Jan 20, 2013

Member

two spaces after :. Also move this #route_table definition above the other one (as the first one).

@carlosantoniodasilva

View changes

actionpack/lib/action_dispatch/middleware/templates/routes/_table.html.erb Outdated
}

#route_table .matched_paths {
border-bottom: solid 3px SlateGrey ;

This comment has been minimized.

Copy link
@carlosantoniodasilva

carlosantoniodasilva Jan 20, 2013

Member

Wrong indent, space before ;.

@carlosantoniodasilva

View changes

actionpack/lib/action_dispatch/middleware/templates/routes/_table.html.erb Outdated
}

#route_table .matched_paths {
background-color: LightGoldenRodYellow ;

This comment has been minimized.

Copy link
@carlosantoniodasilva

carlosantoniodasilva Jan 20, 2013

Member

Wrong indent, space before ;.

</tr>
</thead>
<tbody class='matched_paths' id='matched_paths'>
</tbody>

This comment has been minimized.

Copy link
@carlosantoniodasilva

carlosantoniodasilva Jan 20, 2013

Member

Is it allowed to have as many tbody as we want? Just wondering...

@carlosantoniodasilva

View changes

actionpack/lib/action_dispatch/middleware/templates/routes/_table.html.erb Outdated
// Enables path search functionality
function setupMatchPaths() {
var regex_elems = document.querySelectorAll('#route_table [data-regex]');
var path_elem = document.querySelector('#path_search')

This comment has been minimized.

Copy link
@carlosantoniodasilva

carlosantoniodasilva Jan 20, 2013

Member

No ; at the end.

@carlosantoniodasilva

View changes

actionpack/lib/action_dispatch/middleware/templates/routes/_table.html.erb Outdated
var regex_elems = document.querySelectorAll('#route_table [data-regex]');
var path_elem = document.querySelector('#path_search')
var selected_section = document.querySelector('#matched_paths');
var no_match_text = '<tr><th colspan="4">None</th></tr>';

This comment has been minimized.

Copy link
@carlosantoniodasilva

carlosantoniodasilva Jan 20, 2013

Member

Actually you could use one var declaration only.

This comment has been minimized.

Copy link
@carlosantoniodasilva

carlosantoniodasilva Jan 20, 2013

Member

And change variables names to be camelCase.

This comment has been minimized.

Copy link
@schneems

schneems Jan 20, 2013

Author Member

It's not often that I get the opportunity to refactor javascript code... can you give me more information by what you mean by only using one var declaration?

@kuraga

This comment has been minimized.

Copy link

commented on 8b72d68 Jan 21, 2013

👎 I think info pages should provide minimal information only.

This comment has been minimized.

Copy link
Contributor

replied Jan 22, 2013

I think this is good.
Right now I am just using rake routes and it is slow

This comment has been minimized.

Copy link

replied Jan 24, 2013

@kuraga - little things like this go a long way to keep developers happy. Happy developers are what keep the framework thriving.
It would be nice if the inline javascripts and stylesheets are cleaned up to external assets as it seems like a long step backwards, but this looks to match the rest of templates implementations.
@schneems - thanks for your work. This is great stuff.

This comment has been minimized.

Copy link

replied Jan 28, 2013

To get this feature on non Rails 4 versions, install schneem's gem, Sextant

This comment has been minimized.

Copy link
Contributor

replied Jan 29, 2013

@eric-hu Thanks!

@lukeholder

This comment has been minimized.

@brblck

This comment has been minimized.

Copy link

commented Jan 22, 2013

very nice

@iampeter

This comment has been minimized.

Copy link

commented Jan 24, 2013

👍

@flexoid

This comment has been minimized.

Copy link
Contributor

commented Jan 24, 2013

That's just awesome! 👍

@miguelff

This comment has been minimized.

Copy link

commented Jan 24, 2013

Awesome! ❤️

@pedrosnk

This comment has been minimized.

Copy link

commented Jan 24, 2013

lovely

@sir-pinecone

This comment has been minimized.

Copy link

commented Jan 24, 2013

👍 👍 👍

@bsodmike

This comment has been minimized.

Copy link
Contributor

commented Jan 24, 2013

Dude @schneems ❤️ .... 👍 👍

@tkbeili

This comment has been minimized.

Copy link

commented Jan 24, 2013

👍

@ravidsrk

This comment has been minimized.

Copy link

commented Jan 24, 2013

Awesome stuff <3

@meiraleal

This comment has been minimized.

Copy link

commented Jan 24, 2013

awesome! 😍

@jltxwesley

This comment has been minimized.

Copy link

commented Jan 24, 2013

Awesome!!!

@camsong

This comment has been minimized.

Copy link
Contributor

commented Jan 25, 2013

Amazing 👍

@wizztjh

This comment has been minimized.

Copy link

commented Jan 25, 2013

+1

@jwo jwo referenced this pull request Jan 25, 2013
@hujinpu

This comment has been minimized.

Copy link

commented Jan 25, 2013

Nice feature!

@jankeesvw

This comment has been minimized.

Copy link
Contributor

commented Jan 25, 2013

Nice work! 👍

@ahmet

This comment has been minimized.

Copy link

commented Jan 25, 2013

Nice 👍

@jipiboily

This comment has been minimized.

Copy link
Contributor

commented Jan 25, 2013

❤️

@josin

This comment has been minimized.

Copy link

commented Jan 25, 2013

Good job! 👍

@passion8

This comment has been minimized.

Copy link
Contributor

commented Jan 25, 2013

very good job,thanks
👍

@peppyheppy

This comment has been minimized.

Copy link

commented Jan 26, 2013

👍 I like. (the gif and the PR)

@FUT

This comment has been minimized.

Copy link

commented Jan 28, 2013

great!

@ehrktia

This comment has been minimized.

Copy link

commented Jan 29, 2013

amazed

@djbender

This comment has been minimized.

Copy link

commented Jan 29, 2013

👍

@tubbo

This comment has been minimized.

Copy link

commented Jan 29, 2013

love it, but what happens if i want to do rails g resource rails? i wanna be meta!!1 ;-) :shipit:

@ghost

This comment has been minimized.

Copy link

commented Jan 30, 2013

tumblr_ma97kgGJmQ1qft9ueo1_500

@rahul100885

This comment has been minimized.

Copy link
Contributor

commented Feb 9, 2013

Just awesome

@krishnasrihari

This comment has been minimized.

Copy link

commented Mar 20, 2013

Awesome

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
You can’t perform that action at this time.