百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
R

rack-dev-mark

> 后端框架
开源

在开发环境中显示设备标记

355 stars0 点赞3 次浏览
访问官网GitHub

工具介绍

在开发环境中显示设备标记

rack-dev-mark

Gem Version Download Dependency Status Build Status Coverage Status Code Climate

Differentiate development environment from production. You can choose themes to differentiate the page.

The running sample is available.

You can also try this gem on Heroku.

Screenshot

On Development Env

On Production Env

Installation

Add the rack-dev-mark gem to your Gemfile.

ruby
gem "rack-dev-mark"

And run bundle install.

For Rack App

ruby
require 'rack/dev-mark'
use Rack::DevMark::Middleware
run MyApp

Middleman

Add the settings in config.rb.

ruby
require 'rack/dev-mark'
Rack::DevMark.env = "Your Env"
use Rack::DevMark::Middleware

For Rails App

In config/environments/development.rb

ruby
Rails.application.configure do
  config.rack_dev_mark.enable = true
end

Or In config/application.rb

ruby
module MyApp
  class Application < Rails::Application
    config.rack_dev_mark.enable = !Rails.env.production?
  end
end

Or Alternatively, use generator

bash
bundle exec rails g rack:dev-mark:install

The middleware sets title and github_fork_ribbon themes as default.

Exclude Multiple Environments in Rails

Show the dev mark except env1, env2, env3.

In config/application.rb

ruby
module MyApp
  class Application < Rails::Application
    config.rack_dev_mark.enable = !%w(env1 env2 env3).include?(Rails.env)
  end
end

Rails on Heroku

Since Heroku uses production env for staging. You can't use the settings above. However, the gem provide an easier way to set it up on Heroku. Just set the environment variable on the environment in which you want to show the mark.

bash
heroku config:set RACK_DEV_MARK_ENV=staging

That's it!

Custom Rack Middleware Order

rack-dev-mark should be inserted before ActionDispatch::ShowExceptions becase we want to show the dev mark on the error pages as well. However, it does not work well if it's inserted by incorrect order with some other rack middlewares. So, it provides the setting of inserted place.

ruby
module MyApp
  class Application < Rails::Application
    config.rack_dev_mark.insert_before SomeOtherMiddleware
  end
end

config.rack_dev_mark.insert_after is also available to insert rack-dev-mark after a middleware.

Here is the compatibility list which many people often ask.

Custom env string

Set the custom env string maually.

ruby
module MyApp
  class Application < Rails::Application
    config.rack_dev_mark.env = 'foo'
  end
end

Temporarily disable the dev mark

skip_rack_dev_mark controller helper works like around_filter.

ruby
class FooController < ApplicationController
  skip_rack_dev_mark only: [:iframe]

  def index
    # Do something
  end

  def iframe
    # Do something
  end
end

In this case, only index action will insert the dev mark.

I18n Support

Get i18n string with rack_dev_mark locale strings.

e.g. In config/locale/rack_dev_mark.ja.yml

ja:
  rack_dev_mark:
    development: '開発中'
    staging: 'ステージング'

Then, you will get translated string on the pages!

Custom Theme

Although the default themes are title and github_fork_ribbon, you can create your own themes inheriting Rack::DevMark::Theme::Base.

ruby
require 'rack/dev-mark/theme/base'

class NewTheme < Rack::DevMark::Theme::Base
  def insert_into(html, env, params = {})
    # Do something for your theme
    html
  end
end

class AnotherTheme < Rack::DevMark::Theme::Base
  def insert_into(html, env, params = {})
    # Do something for your theme
    html
  end
end

Then, insert them in your app.

For Rack App

ruby
use Rack::DevMark::Middleware, [NewTheme.new, AnotherTheme.new]

For Rails App

In config/application.rb

ruby
module MyApp
  class Application < Rails::Application
    config.rack_dev_mark.theme = [NewTheme.new, AnotherTheme.new]
  end
end

You can add any combination of themes. See more about themes.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Release

With gem-release:

bash
bundle exec gem bump --version patch --tag --push
bundle exec gem release

--pretend is not a dry run here: it has been observed to commit, tag, push and release for real.

Copyright

Copyright (c) 2014 Daisuke Taniwaki. See LICENSE for details.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Rubydevrackrails

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类后端框架
定价开源

> 相关工具

N
Node.js
基于 V8 的 JavaScript 运行时
D
Django
Python 高级 Web 框架
S
Spring Boot
Java 生态主流微服务框架