shou2017.com
JP

Rails: Applying Classes to form_for in Devise

Sun Dec 9, 2018
Sat Aug 10, 2024

I made a mistake while applying classes to form_for when styling Rails Devise with Semantic UI, so here’s a note about it.

Incorrect Method

<form class="ui large form">
  <div class="ui stacked segment">
    <%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>

Correct Method

By adding :html => {:class => 'ui large form'} to form_for, the class is properly applied.

<%= form_for(resource, as: resource_name, :html => {:class => 'ui large form'}, url: registration_path(resource_name)) do |f| %>
  <div class="ui stacked segment">
See Also