Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/inouridder/draw_static
Generating routes for static controller
https://github.com/inouridder/draw_static
for generator rails routes static
Last synced: 2 months ago
JSON representation
Generating routes for static controller
- Host: GitHub
- URL: https://github.com/inouridder/draw_static
- Owner: InouRidder
- Created: 2019-04-18T11:39:23.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-04-29T12:36:06.000Z (almost 5 years ago)
- Last Synced: 2024-11-18T04:04:10.615Z (3 months ago)
- Topics: for, generator, rails, routes, static
- Language: Ruby
- Homepage:
- Size: 42 KB
- Stars: 8
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# draw_static
## Cleaning up your static routes in rails
```
get 'home', to: 'pages#home'
get 'about', to: 'pages#about'
get 'contact-us', to: 'pages#contact_us'
```### Familiar?
Add
```
# Gemfile
gem 'draw_static'
```
To the Gemfile and then run bundle install, then add```
# routes.rbRails.application.routes.draw do
draw_static :pages # Or which controller you are using for static routes
end
```This set up will generate the static routes based on the controller actions.
In this case we are generating the routes for the PagesController, if you want to do it for your PublicPagesController then you would pass: :public_pagesThe controller action has to be the same name as the path. All non-word characters in the controller actions name are replaced by hyphens in the path.
e.g
```
def about_us
end
```
Will become
```
get 'about-us', to: 'pages#about_us'
```### Multiple controllers
You can specify as many controllers as you like.```
# routes.rbRails.application.routes.draw do
draw_static :pages, :public, :sales # Or which controller you are using for static routes
end```
### Limits
```
# You can limit the routes that are generated by using except or onlydraw_static :pages, only: [:home, :contact]
draw_static :pages, except: [:contact]# also works for multiple controllers
draw_static :pages, :public, except: [:home, :contact]
# actions called either contact or home will be filtered from all controllers.
```
### Enjoy!
### Rails
draw_static is a gem for the rails framework, read more about the rails frame work here
https://github.com/rails/rails