profile
viewpoint
If you are wondering where the data of this site comes from, please visit https://api.github.com/users/glasserc/events. GitMemory does not store any data, but only uses NGINX to cache data for a period of time. The idea behind GitMemory is simply to give users a better reading experience.

glasserc/ethan-wspace 97

the definitive emacs customizations for people who are OCD about whitespace

glasserc/etc 3

my configuration files

glasserc/bin 2

throwaway scripts I've developed

glasserc/elm-requested 2

An opinionated library for managing requests

glasserc/demo-elm-structures 1

Just a scratchpad to play around with some small-scale Elm architecture principles

glasserc/fatcopy 1

Copy and rename to comply with FAT filename restrictions

glasserc/graphpaper 1

prototype digital-graph-paper program

glasserc/application-services 0

Firefox Application Services

glasserc/beancount-mode 0

Emacs and other editor support for editing Beancount files.

glasserc/bigquery-etl 0

Bigquery ETL

issue commentrails/rails

Path helpers can be generated for namespace rather than a specific endpoint

To be honest, I care more about the absence of ethan_is_cool_path (which I think is misleading) than about any specific route for the users path.

Yes, it's true that I could use as to "cover up" the misleading route, but it's a little bit of a footgun since other routes could "inherit" the name or another endpoint could be added later that reintroduces the misleading name.

I think the observation that resource and resources are normalized or preferred is an interesting one. The documentation says in section 3 that "While you should usually use resourceful routing, there are still many places where the simpler routing is more appropriate." My reading of this is that non-resourceful routing is of equal status with resourceful routing. I am open to the possibility that the problem is my understanding, but in that case I would request that the documentation be clarified.

glasserc

comment created time in 2 months

issue commentrails/rails

Path helpers can be generated for namespace rather than a specific endpoint

I'm also pretty new to Rails so my opinion may not be valuable, but based on my co-worker's comment, I would not expect a helper for the first or last route, and the second route's helper is fine as it is.

glasserc

comment created time in 2 months

issue openedrails/rails

Path helpers can be generated for namespace rather than a specific endpoint

Steps to reproduce

I've created a simple Rails application for the sake of debugging which has the following config/routes.rb:

Rails.application.routes.draw do
  namespace :ethan_is_cool do
    scope path: "/:message" do
      get "/go_big", to: "transformations#uppercase"
    end
    get "/profile", to: "profile#index"
    get "/users/:id", to: "users#show"
  end
end

Expected behavior

Helpers would be generated for certain endpoints within the namespace, prefixed by ethan_is_cool_, for example ethan_is_cool_profile_path for profile#index. It would be obvious which endpoint corresponded to which helper.

Actual behavior

An ethan_is_cool route appears to be generated. rails routes --grep ethan_is_cool shows:

               Prefix Verb URI Pattern                              Controller#Action
 ethan_is_cool_go_big GET  /ethan_is_cool/:message/go_big(.:format) ethan_is_cool/transformations#uppercase
ethan_is_cool_profile GET  /ethan_is_cool/profile(.:format)         ethan_is_cool/profile#index
        ethan_is_cool GET  /ethan_is_cool/users/:id(.:format)       ethan_is_cool/users#show
irb(main):001:0> Rails.application.routes.url_helpers.ethan_is_cool_path(id: 1)
=> "/ethan_is_cool/users/1"

This behavior is different from what happens if you unwrap the namespace call -- in this case, no helper is generated for this route, as expected.

This behavior is also different from what happens if you replace the scope call with the presumably-equivalent get "/:message/go_big", to: "transformations#uppercase". In this case, an ethan_is_cool_path helper is generated but it points to the go_big route rather than the users route. The effect is that this refactor breaks any use of the ethan_is_cool_path helper as well as the ethan_is_cool_go_big_path helper. (Of course, if you also unwrap the namespace call, no helper is generated for either route).

Additionally, I had a really hard time figuring out whether this behavior was expected or not. https://guides.rubyonrails.org/routing.html emphasizes resourceful routing and there is no overall explanation of what circumstances helpers are generated in or what controls them. I learned from a co-worker a rule of thumb that they are generated from the path (not the controller, action or method) and typically not generated when there are dynamic segments in the path. A paragraph or two on that document, or another document if it makes more sense, would be very helpful to learners like me.

System configuration

Rails version: 6.1.3.2

Ruby version: 2.7.1p83

created time in 2 months

push eventglasserc/etc

Ethan Glasser-Camp

commit sha 215136048f7728d85c5f4aa258d0572265139eb3

I actually never use this

view details

Ethan Glasser-Camp

commit sha 7e72ba1e18096cc706c56daff2e8dc19bf477413

Try to use this more, especially in Rubyland

view details

push time in 3 months

push eventglasserc/etc

Ethan Glasser-Camp

commit sha d69d9af2ff87d21f01f91a5893924a9ec10382be

Looks like magit binds this by default!

view details

Ethan Glasser-Camp

commit sha 97fde02324e0f2d3dfa75a990f60617be6e4401f

Just discovered this binding

view details

Ethan Glasser-Camp

commit sha de18fd5471498893224a9aa2ed1477499a8bdd3d

Merge branch 'master' of github.com:glasserc/etc

view details

push time in 3 months