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

rails_icons

> 后端框架
开源

将任何图标库添加到 Rails 应用中。支持 Lucide、Phosphor、Heroicons 等

321 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

将任何图标库添加到 Rails 应用中。支持 Lucide、Phosphor、Heroicons 等

Rails Icons

Add any icon library to a Rails app. Rails Icons has first-party support for a handful of libraries. It is library agnostic so it can be used with any icon library using the same interface. Rails Icons is a Rails gem for the Icons Ruby gem.

erb
# Using the default icon library
icon "check", class: "text-gray-500"

# Using any custom library
icon "apple", library: "simple_icons", class: "text-black"

The icons are sourced directly from their respective GitHub repositories via the Icons gem, ensuring Rails Icons remain lightweight.

Sponsored By Rails Designer

Install

Add the gem:

bash
bundle add rails_icons

Install, choosing one of the supported libraries:

bash
rails generate rails_icons:install --library=LIBRARY_NAME

Example

bash
rails generate rails_icons:install --library=heroicons

# Or multiple at once
rails generate rails_icons:install --libraries=heroicons lucide

# Or only specific variants
rails generate rails_icons:install --library=heroicons --variants solid outline

The generator also mounts an icon preview at /rails_icons where you can browse and search all your available icons. This route is open by default, so restrict it in production if needed.

Usage

…

Sprites

Rails Icons supports SVG sprites for improved performance. Instead of inlining each icon's full SVG, sprite icons reference a shared set of definitions via.

Configuration

…

External sprite (default)

Rails Icons serves the sprite at /rails_icons/sprite.svg out of the box — no controller, route or MIME type setup needed. The endpoint sits at the host app level, so it stays reachable even when the preview engine is mounted behind authentication.

erb

 %>

Point at a precompiled file or a CDN by changing the location:

ruby
config.default_sprite_location = "https://cdn.example.com/sprite_icons.svg"

Override per icon:

erb

Inline sprite

Set the location to nil and embed the sprite directly in your layout:

ruby
config.default_sprite_location = nil
erb

  

  
  
  

You can also generate a sprite for a specific set of icons:

erb

Helpers

sprite_icon accepts the same options as icon:

ruby
sprite_icon "check"
sprite_icon "check", library: "heroicons", variant: "mini"
sprite_icon "check", class: "size-6", data: { controller: "swap" }, stroke_width: 2
sprite_icon "check", sprite_location: "/sprite.svg"

icons_sprite generates the inline containing definitions:

ruby
icons_sprite # all configured icons
icons_sprite ["check", "search"]  # specific icons
icons_sprite ["check", "search"], library: "heroicons", variant: "outline"  # with library/variant

First-party libraries

  • Boxicons (1600+ icons)
  • Feather (280+ icons)
  • Flags (540+ icons)
  • Heroicons (300+ icons)
  • Hugeicons (4600+ icons)
  • Linear (170+ icons)
  • Lucide (1500+ icons)
  • Phosphor (9000+ icons)
  • Radix (300+ icons)
  • SidekickIcons (49 icons, complementing Heroicons)
  • Tabler (5700+ icons)
  • Weather (215+ icons)

Animated icons

Rails Icons also includes a few animated icons. Great for loading states and so on. These are currently included:

  • faded-spinner
  • trailing-spinner
  • fading-dots
  • bouncing-dots

Use like this: icon "faded-spinner", library: "animated". The same attributes as the other libraries are available.

Sync icons

To sync all libraries, run:

bash
rails generate rails_icons:sync

To sync only a specific library, run:

bash
rails generate rails_icons:sync --library=heroicons

# Or multiple at once:
rails generate rails_icons:sync --libraries=heroicons lucide

To sync only specific variants for a library:

bash
rails generate rails_icons:sync --library=heroicons --variants solid outline

Custom icon libraries

Rails Icons pulls SVGs straight from the path //.svg. No generator is required for custom icons. Configuration is optional and only used to define defaults.

To add a custom library, create its directory and drop in your SVGs:

app/assets/svg/icons/simple_icons/apple.svg

(Alternatively, scaffold it with rails generate rails_icons:install --library=simple_icons, which creates the directory and adds config.custom_library :simple_icons in the initializer.)

Use them like any other library:

ruby
icon "apple", library: :simple_icons

To add a git source for syncing, edit the initializer:

ruby
RailsIcons.configure do |config|
  config.custom_library :my_icons, source: {
    url: "https://github.com/user/icons.git",
    variants: { default: "." }
  }
end

Then sync:

bash
rails generate rails_icons:sync --library=my_icons

Projects using Rails Icons

  • Rails Designer UI Components — The first professionally-designed UI components library for Ruby on Rails apps
  • Chirp Form — Add forms to any site. Display responses anywhere
  • Seal Static — Host sites for every need
  • Spinal CMS — Minimal and beautiful CMS for static site generators

Contributing

This project uses Standard for formatting Ruby code. Please make sure to run be standardrb before submitting pull requests. Run tests via rails test.

License

Rails Icons is released under the MIT License.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

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

> 标签

Rubyboxiconsfeather-iconsheroiconsicons

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

> 工具信息

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

> 相关工具

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