Comments (2)
I'm going to expand on this a bit, when using the resources
macro, even though it accepts the block with the other request macros (get
/post
etc) it does not create the routes at all as far as I can tell. This is contrary to what the documentation says.
After doing some digging I found the namespace
macro and it does exactly what you'd expect:
routes :web, "/admin" do
namespace "/users" do
post "/login", UsersController, :login
post "/logout", UsersController, :logout
post "/sign-up", UsersController, :create
end
resources "/users", UsersController, except: [:create]
end
This produces the paths:
/admin/users/show
/admin/users/login
/admin/users/logout
/admin/users/sign-up
I found that when nesting namespaces a little deeper, the amber routes
cli tool does not show the full path. It would show the routes from the original example as if they should work, but they aren't accessible at all when passed in as a block to the resources
macro. They do work as expected when using the namespace
macro.
When I say "deeper" nested, I meant the sign-up
method url being /admin/users/sign-up
, the routes
CLI command will only show the sign-up
end-point belonging to he admin
scope and shows the URI pattern as /sign-up
. So you'd never know if it was actually /admin/sign-up
or /admin/users/sign-up
from the CLI tool.
As best I can tell, this is an issue with the resources
macro and the CLI command, not the amber router itself.
from amber.
I updated my routing example after some further testing. A namespace
that shares a route base with the resource
must be defined before the resource
. Otherwise the route will match to the show
action and will cause an error because the string of the route is not a bigint
That exposes another concern: resource routes appear to be tightly coupled to integers for the actions that require an :id
in the route.
I need to explore this further, because this should be something we can change. Adding a constraints
option for the route, and/or a way to determine what the :id
of the path is should also exist. It's common to change from standard sequential ID's to slugs or UUID's and I want to ensure that Amber supports that type of routing.
from amber.
Related Issues (20)
- Change from Github Actions -> CircleCI
- Improve Installation Documentation & Experience for Windows/Linux Users HOT 4
- `amber g ` creates system tests that are incomplete for controller/request testing
- Improve the Auth generated by `amber g auth` HOT 2
- Feature: Unify the API for config vars HOT 1
- Enhancement: Improving the generators for greater flexibility
- Enhancement: Automatically return 400 response if param validation fails HOT 1
- amber 1.3.2 regression test failure against crystal 1.9.1 HOT 5
- amber 1.4.0 test failure HOT 4
- Requests with `content-type` `application/json` do not parse params correctly
- Automatically generated mock data files
- Create Installation instructions for brew on linux
- Use Ansible to test installation instructions for different OSes HOT 2
- Sqlite dependency version missmatch HOT 1
- Inexistent docker image in generated Dockerfile HOT 2
- First registered connection cannot be nil HOT 2
- Automatically Create and Migrate Test Databases on Linux
- Discord server HOT 4
- Should Generate Controller Specs with `amber generate api`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from amber.