Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
S

superform

> 后端框架
Open source

Build highly customizable HTML forms with Phlex components

392 stars0 likes4 views
WebsiteGitHub

About

Build highly customizable HTML forms with Phlex components

Superform

The best Rails form library. Whether you're using ERB, HAML, or Phlex, Superform makes building forms delightful.

  • No more strong parameters headaches. Add a field to your form and it automatically gets permitted. Never again wonder why your new field isn't saving. Superform handles parameter security for you.

  • Works beautifully with ERB. Start using Superform in your existing Rails app without changing a single ERB template. All the power, zero migration pain.

  • Concise field helpers. Field(:publish_at).date, Field(:email).email, Field(:price).number — intuitive methods that generate the right input types with proper validation.

  • RESTful controller helpers Superform's save and save! methods work exactly like ActiveRecord, making controller code predictable and Rails-like.

Superform is a complete reimagining of Rails forms, built on solid Ruby foundations with modern component architecture under the hood.

Video course

Support this project and become a Superform pro by ordering the Phlex on Rails video course.

Installation

Add to the Rails application's Gemfile by executing:

$ bundle add superform

Then install it.

$ rails g superform:install

This will install both Phlex Rails and Superform.

Usage

Start with inline forms in your ERB templates

Superform works instantly in your existing Rails ERB templates. Here's what a form for a blog post might look like:

erb

New Post

The form automatically generates proper Rails form tags, includes CSRF tokens, and handles validation errors.

Notice anything missing? Superform doesn't need `` tags around every single line, unlike all other Rails form helpers.

Extract inline forms to dedicated classes to use in other views

You probably want to use the same form for creating and editing resources. In Superform, you extract forms into their own Ruby classes right along with your views.

ruby
# app/views/posts/form.rb
class Views::Posts::Form 

Cool, but you're about to score a huge benefit from extracting forms into their own Ruby classes with automatic strong parameters.

Automatically permit strong parameters with form classes

Include Superform::Rails::StrongParameters in your controllers for automatic parameter handling:

ruby
class PostsController 

Much better!

Customizing radios and checkboxes

radios and checkboxes render sensible defaults out of the box, but you can subclass them to match your design system. Override view_template to change the default markup — the block form still works for one-off customizations.

…

Render it with ``. For file uploads, pass enctype: "multipart/form-data" to the form constructor.

Extending Superforms

The best part? If you have forms with a completely different look and feel, you can extend the forms just like you would a Ruby class:

ruby
class AdminForm 

  Benefits
  
    
    
  
ruby
# Superform — one-liner
Field(:benefit_ids).checkboxes(Benefit.select(:id, :name))

# Or with custom markup
fieldset do
  legend { "Benefits" }
  Field(:benefit_ids).checkboxes(Benefit.select(:id, :name)) do |choice|
    choice.label {
      choice.input
      whitespace
      plain choice.text
    }
  end
end

Superform handles the field name (benefit_ids[]), checked state, unique ids, and label targeting automatically. The same pattern works for radio groups with radios(...).

With Superform, you build the entire form with Ruby code, so you avoid the Erb gymnastics and helper method soup that it takes in Rails to scale up forms in an organization.

Simple Form

I built some pretty amazing applications with Simple Form and admire its syntax. It requires "Erb soup", which is an opening and closing line of Erb per line. If you follow a specific directory structure or use their component framework, you can get pretty far, but you'll hit a wall when you need to start putting wrappers around forms or inputs.

https://github.com/heartcombo/simple_form#the-wrappers-api

The API is there, but when you change the syntax, you have to reboot the server to see the changes. UI development should be reflected immediately when the page is reloaded, which is what Superforms can do.

Like Rails form helpers, it doesn't self-permit parameters.

https://www.ruby-toolbox.com/projects/simple_form

Formtastic

Formtastic gives us a nice DSL inside of Erb that we can use to create forms, but like Simple Form, there's a lot of opening and closing Erb tags that make the syntax clunky.

It has generators that give you Ruby objects that represent HTML form inputs that you can customize, but its limited to very specific parts of the HTML components. Superform lets you customize every aspect of the HTML in your form elements.

It also does not permit its own parameters.

https://www.ruby-toolbox.com/projects/formtastic

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To preview example forms in your browser, run:

$ bin/preview

This boots a local Rails server at http://localhost:3000 that displays all forms in the examples/ directory. The server supports hot-reloading, so you can edit forms and refresh the page to see changes.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and the created tag, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/rubymonolith/superform. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the Superform project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Rubyphlexrails

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category后端框架
PricingOpen source

> Related tools

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