button button f

Welcome to button button f

How to make a rails form_for submit button a bootstrap button - Stack Overflow

2024.09.24 19:36


Skip to main content Stack Overflow About Products OverflowAI Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers Advertising & Talent Reach devs & technologists worldwide about your product, service or employer brand OverflowAI GenAI features for Teams OverflowAPI Train & fine-tune LLMs Labs The future of collective knowledge sharing About the company Visit the blog

current community

Stack Overflow help chat Meta Stack Overflow

your communities

Sign up or log in to customize your list.

more stack exchange communities

company blog Log in Sign up Home Questions Tags Users Companies Labs Jobs Discussions Recent Tags Collectives

Communities for your favorite technologies. Explore all Collectives

Teams

Now available on Stack Overflow for Teams! AI features where you work: search, IDE, and chat.

Learn more Explore Teams Teams

Ask questions, find answers and collaborate at work with Stack Overflow for Teams. Explore Teams

Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

Get early access and see previews of new features.

Learn more about Labs

How to make a rails form_for submit button a bootstrap button

Ask Question Asked 9 years, 11 months ago Modified 2 years, 11 months ago Viewed 19k times 12

I am trying to make my rails form_for submit button look like the bootstrap btn btn-lg btn-primary button. I've tried a few different ways and have found no success. The best I could get is getting the form_for submit button in the center of a bootstrap button with different colors. Does anyone know what the command would be to get the bootstrap button to perform the action that my f.submit button does.

div class="Action" %= f.submit % /div ruby-on-rails twitter-bootstrap Share Improve this question Follow edited Oct 22, 2014 at 3:12 Yu Hao 122k 47 47 gold badges 244 244 silver badges 303 303 bronze badges asked Oct 22, 2014 at 2:56 Billy Billy 843 3 3 gold badges 13 13 silver badges 29 29 bronze badges Add a comment |

4 Answers 4

Sorted by: Reset to default Highest score (default) Trending (recent votes count more) Date modified (newest first) Date created (oldest first) 21 = f.submit :Submit, class: 'btn btn-success' Share Improve this answer Follow answered Oct 22, 2014 at 3:00 OneChillDude OneChillDude 7,956 10 10 gold badges 42 42 silver badges 80 80 bronze badges 2 I get the error undefined local variable or method f – Whitecat Commented Jun 23, 2017 at 16:24 1 @Whitecat f is the form object, in a rails scaffold it s form e.g. form.submit – stevec Commented Jul 23, 2021 at 17:17 Add a comment | 10

By default %= f.submit % will create an input element according to the docs .

If you want to make it an actual button /button element, you can do it like this:

%= f.button My Button , type: submit , :class= btn btn-primary %

Share Improve this answer Follow answered Oct 21, 2021 at 20:11 ricks ricks 3,254 36 36 silver badges 55 55 bronze badges Add a comment | 2

Not clear from the docs: if you still want the form_for to set the button name to ' Update class ' or ' Create class ' then pass nil into the submit:

%= form.submit nil, class: 'btn btn-success' % Share Improve this answer Follow answered Dec 10, 2019 at 4:07 phil phil 4,878 4 4 gold badges 37 37 silver badges 55 55 bronze badges Add a comment | 1 = f.submit :Submit, class: 'btn btn-success'

or

= f.submit :Submit, class: :btn, class: :btn-success

Anyone getting errors on:

undefined local variable or method 'f'

Check what your form variable name is. It will appear when you're declaring a form such as:

form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| Share Improve this answer Follow answered Oct 14, 2017 at 23:46 Zitzabis Zitzabis 178 8 8 bronze badges 1 other likely cause for undefined local variable or method f is that maybe you are using f.submit ouside the scope of the form_for block, where f is available. – Juan José Ramírez Commented Jun 8, 2021 at 19:21 Add a comment |

Not the answer you're looking for? Browse other questions tagged ruby-on-rails twitter-bootstrap or ask your own question .

The Overflow Blog Where developers feel AI coding tools are working—and where they’re missing He sold his first company for billions. Now he’s building a better developer Featured on Meta User activation: Learnings and opportunities Preventing unauthorized automated access to the network Announcing the new Staging Ground Reviewer Stats Widget Should low-scoring meta questions no longer be hidden on the Meta.SO home

Related

0 ruby on rails using bootstrap - prepend text and append button to an input field in a form 2 Modifying Bootstrap form s submit button to custom css 2 aligning rails form_for button integrated with bootstrap 1 Substitute a Rails form submit button by a Bootstrap icon 0 submit button in rails app is not using twitter bootstrap styling 1 Applying a Bootstrap class to form_for in Rails 1 In Ruby on Rails, how to customize the submit button to use BootStrap and add a icon to it? 0 making rails form_for compatible with bootstrap form w/o using a gem. 7 make rails link as bootstrap button 1 Line up a form_for button in a bootstrap btn-group in rails

Hot Network Questions

VLA configuration locations Could you suffocate someone to death with a big enough standing wave? US Visa Appointment error: Your personal details match a profile which already exists in our database Soldering a thermal fuse. 92°C \usepackage[ language ]{babel} or \babelprovide{ language }? Why? Firefox isn't upgraded on Debian: its ESR has 1.5 years old, ensuring it being discarded. How to ask a global upgrade from Debian or Mozilla team? What exactly is a scratch file (starting with #)? Does it still work today? U.S Citizen married to Danish Citizen living in Sweden with active resident card application - Can we travel to Denmark together? What is a Locus? If a professor wants to hire a student themselves, how can they write a letter of recommendation for other universities? Is there a way to have my iPhone register my car which doesn't have carplay, only for the Car is parked at -feature? What made scientists think that chemistry is reducible to physics and when did that happen? Should punctuation (comma, period, etc.) be placed before or after the inches symbol when listing heights? Could a Project like Orion be built today with non nuclear weapons? Breeding Fish Minecraft Minimal dominating sets in thin hypergraphs According to Trinitarians, how could Jesus (God the Son) be GIVEN life in Himself (John 5:26), if he shares the same essence of being than the Father? Do all languages distinguish between persons and non-persons? Load center and main breaker sharing same lugs at service entrance How to apply a function to specific rows of a matrix How to return multiple columns from one function inside `mutate` and allow me to name the output columns? Bridge in a walled garden Why aren't some conditions officially a condition? (Burning, Bloodied) Did Gauss really call Archimedes an idiot? more hot questions Question feed

Subscribe to RSS

Question feed

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

default
Stack Overflow
Questions Help Chat
Products
Teams Advertising Talent
Company
About Press Work Here Legal Privacy Policy Terms of Service Contact Us Cookie Settings Cookie Policy
Stack Exchange Network
Technology Culture & recreation Life & arts Science Professional Business API Data Blog Facebook Twitter LinkedIn Instagram

Site design / logo © 2024 Stack Exchange Inc; user contributions licensed under CC BY-SA . rev 2024.9.23.15701



Vivamus fermentum nibh