GithubHelp home page GithubHelp logo

aymeric-ledorze / rails-static-router Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mufid/rails-static-router

0.0 0.0 0.0 41 KB

Enjoy static routes in your Rails config/routes.rb

License: MIT License

Ruby 80.24% HTML 19.76%

rails-static-router's Introduction

Rails Static Router Build Status Gem Version

Enjoy static routes in your Rails config/routes.rb.

Installation

  1. Put gem 'rails-static-router' in your Gemfile
  2. Restart app

Example use

Rails.application.routes.draw do
  ...
  # This route will serve public/index.html at the /login URL path, and have
  # URL helper named `login_path`:
  get "/login", to: static("index.html")

  # This route will serve public/index.html at the /register URL path, and
  # have URL helper named `new_user_registration_path`:
  get "/register", to: static("index.html"), as: :new_user_registration
  ...
end

bin/rake routes output for the above routes:

               Prefix  Verb  URI Pattern          Controller#Action
                login  GET   /login(.:format)     static('index.html')
new_user_registration  GET   /register(.:format)  static('index.html')

Compatibility

This gem is compatible with Rails 4.1+.

Rails API Mode

We don't recommend use this gem if you are using Rails API Mode. Your apps supposed to only serving API, not assets.

Why?

This introduces a static(path_to_file) helper method to route to static files from within routes.rb. It is inspired by Rails' existing redirect(...) method.

Some benefits of this technique over alternatives (such as rack-rewrite, nginx/httpd-configured rewrites):

  • Named URL helper method for static file available throughout app, for example in mail templates, view templates, and tests.

  • Route discoverable via bin/rake routes and Routing Error page in development.

  • Takes advantage of ActionDispatch's built-in gzip handling. Controller action based solutions for rendering static files tend to not use this.

  • Handy for Single Page Apps that serve the same static HTML file for multiple paths, as is often the case with Ember & Angular apps.

  • Heroku-like production environments work with this that do use the Rails app to serve static files.

  • Leaves door open for nginx, Apache, Varnish and friends to serve the static files directly for improved performance in production environments via symlinks and/or other artifacts generated at deploy time.

Contributors

  • Eliot Sykes https://eliotsykes.com/
  • Muhammad Mufid Afif https://mufid.github.io
  • Your name here! Contributions are welcome and easy. Fork the GitHub repo, make your changes, then submit your pull request. Don't hesitate to ask if you'd like some help.

Contributing

We are using Appraisals to test against multiple Rails version. To set it up for the first time, please run:

bundle install
bundle exec appraisal install

After Appraisal installed, use this command to run all the test:

bundle exec appraisal rake test

To run against only specific Rails version, you can specify it with BUNDLE_GEMFILE. For example, if you want to run only against Rails 5.2, you can execute command below.

export BUNDLE_GEMFILE=gemfiles/rails51.gemfile
bundle install
bundle exec rake test

To test it agains multiple Ruby version, you may want to use rvm. For example:

# Test it against all specified Rails version
# with Ruby version 2.3.7
rvm install 2.3.7
rvm use 2.3.7
bundle exec appraisal rake test

# Test it against all specified Rails version
# with Ruby version 2.4.4
rvm install 2.4.4
bundle exec appraisal rake test

Releasing

For contributors that have access to release server, do the following commands to release the gem.

# Edit version.rb to match next version, then
git add .
git commit -m "ops: <NEXT_VERSION> release"
bundle exec rake release

rails-static-router's People

Contributors

mufid avatar eliotsykes avatar aymeric-ledorze avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.