Añadir una clase CSS a < % = f. submit %>


Mi pregunta es fácil:

<%= f.submit %>

¿A dónde va la declaración de clase? Estoy recibiendo errores en múltiples intentos.

Author: sscirrus, 2011-03-15

6 answers

<%= f.submit 'name of button here', :class => 'submit_class_name_here' %>

Esto debería bastar. Si usted está recibiendo un error, lo más probable es que usted no está proporcionando el nombre.

Alternativamente, puede estilizar el botón sin una clase:

form#form_id_here input[type=submit]

Prueba eso también.

 334
Author: Srdjan Pejic,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-03-15 18:07:29

Puede agregar una declaración de clase al botón enviar de un formulario haciendo lo siguiente:

<%= f.submit class: 'btn btn-default' %>

Si está alterando un formulario _.HTML.erb parcial de un andamio y desea mantener el cambio dinámico del nombre del botón entre las acciones del controlador, NO especifique un nombre 'name'.

Sin especificar un nombre y dependiendo de la acción que se renderice el formulario, el botón obtendrá el .class = "btn btn-default" (clase Bootstrap)(o lo que sea .class que especifíquese) con los siguientes nombres:

  • Actualización model_name

  • Crear nombre_modelo
    (donde model_name el nombre del modelo del andamio)

 121
Author: aloucas,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-09-10 14:45:01

Rails 4 y Bootstrap 3 botón "primario"

<%= f.submit nil, :class => 'btn btn-primary' %>

Produce algo como:

Pantalla-2014-01-22_02.24.26.png http://img854.imageshack.us/img854/9148/2wlx.png

 25
Author: cwd,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-01-22 07:25:22

Como dice Srdjan Pejic, puede usar

<%= f.submit 'name', :class => 'button' %>

O la nueva sintaxis que sería:

<%= f.submit 'name', class: 'button' %>
 11
Author: RailsZilla.com,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-05-10 11:38:14

De forma predeterminada, Rails 4 utiliza el atributo' value ' para controlar el texto del botón visible, por lo que para mantener el marcado limpio usaría

<%= f.submit :value => "Visible Button Text", :class => 'class_name' %>
 2
Author: benjamin.patch,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-08-29 23:06:32

Rails 5.2 Solución:

Para aquellos que usan Rails 5.2 el ayudante withform_with: no agregue la coma!

<%= f.submit class: 'btn btn-primary' %>

Captura de pantalla sin coma

HTH!

 2
Author: BKSpurgeon,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-09-02 07:23:14