Advanced routes

2 questions

  1. How do I declare singular routes
    example resource :geocoder
    Rails documentation link (https://guides.rubyonrails.org/routing.html#singular-resources)

  2. How do I restrict resource methods
    example resources :users, only: [:show]

Looks like I have to declare them explicitly instead of using resource/resources. But wanted to check here.

Don’t have support for this yet.

Also missing this.

Yup, have to declare them explicitly currently. Will dig into this, unsure when. Happy to consider pull requests though :ok_hand:

Jets routing is built really from the ground up. It works pretty differently to account for API Gateway. So it’s doesn’t have a lot of the extras helpers like in the Rails routes yet. Would like them to be added over time. Happy to consider pull requests for this. One nice benefit is that I’m so hoping the implementation will simpler.

Thank you for quick reply. This makes sense, so I’m going with explicit routes.

@tung any update on resources :users, only: [:show]? It would be nice to have that feature. I’ll be more than happy to submit a PR. Heads up?

Released in Jets v2.0.0 :tada:

https://rubyonjets.com/docs/routing/guide/

1 Like

Wow that is fantastic news.

Hi @tung
Thank you for making this update. I think this may help me resolve #198.

In rails, I can use Rails.application.routes.url_helpers, what would be equivalent method in Jets?
I tried Jets.application.routes.url_helpers but that didn’t work

Interesting. An equivalent routes.url_helpers does not yet exist in Jets. Guessing you’re including it in models so you can use url helpers outside of views.

Will look at it in time. Will consider PRs for this. :+1:

I was using them in Rspec for my serializer specs.
Looks like they look for this line under Rspec config for Rails

config.include Rails.application.routes.url_helpers

I’m happy to raise a PR, can you point me to some files/direction where I should start?

Think I would start with the Jets::Router::Helpers module.

This contains Jets core and generated named routes helpers. Then would figure out how to include the ActionView helpers also.

FWIW, if all you need are the named routes helpers. include Jets::Router::Helpers may be enough for what you’re trying to do. Took a different approach with the Jets implementation. It “compiles” down routes code to generate the methods and doesn’t need to reference the view scope.

Route helpers added to spec helpers in #332 Released in v2.0.4

What would be equivalent to Rails.application.routes.url_helpers in Jets?

RE: Rails.application.routes.url_helpers

Oh, missed this. Will dig into it in time. Happy to also consider PRs.