vitoravelino / modular_routes Goto Github PK
View Code? Open in Web Editor NEWDedicated controllers for each of your Rails route actions.
License: Apache License 2.0
Dedicated controllers for each of your Rails route actions.
License: Apache License 2.0
Rails.application.routes.draw do
modular_routes do
resources :app, only: %i[index]
get '/:slug', to: 'tenant_home#index', as: :slug
end
end
If you set this on config/routes.rb
when you go to /app
it redirects to /:slug
But if you set this on config/routes.rb
works properly
Rails.application.routes.draw do
get '/app', to: 'app/index#call', as: :app
get '/:slug', to: 'tenant_home/index#call', as: :slug
end
The idea is to pass an option to modular_routes
helper that will overwrite the default controller method name call
.
An example of that could be:
# routes.rb
modular_routes controller_method: :execute do
resources :books, only: :index
end
# controllers/books/index.rb
module Books
class IndexController
def execute
# ...
end
end
end
The current support is tied to resource(s). It would be nice to support without that like:
modular_routes do
get "/about", to: "about#index"
post "/setup", to: "setup#create"
end
It would be the same as:
get "/about", to: "about/index#call"
post "/setup", to: "setup/create#call"
The gain of simplicity is not as big as it is for resources but it would be nice to have the possibility.
Sometimes you might have api endpoints being served within the same traditional web app. Having a way of ignoring :edit
and :new
would be nice.
# routes/web.rb
modular_routes do
resources :books
end
# routes/api.rb
modular_routes(api: true) do
resources :books
end
modular_routes do
concern :commentable do
resources :comments
end
# as option
resources :books, concerns: :commentable
# or inside block
resources :books do
concerns :commentable
end
# within namespace
namespace :articles do
concerns :commentable
end
end
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.