Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6884937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:34:18+00:00 2026-05-27T05:34:18+00:00

I need implements a helper that creates <button>…</button> tag, I need to do some

  • 0

I need implements a helper that creates <button>...</button> tag, I need to do some similar to this:

<%= form_for(some_var) do |f| %>
  <%= f.submit '+' %>
<% end %>

The helper should work like this:

<%= f.button '+' %>
# Returns
<button type="submit">+</button>

I saw https://github.com/rails/rails/blob/master/actionpack/lib/action_view/helpers/form_tag_helper.rb#L458 but this isn’t implemented in Rails 3.0.7.

What I need to do to implements this helper in my application?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T05:34:19+00:00Added an answer on May 27, 2026 at 5:34 am

    You can create a custom form helper that inherits from FormBuilder to use when creating forms. I created this button method to use with Twitter’s Bootstrap.

    Replace ‘Bootstrap’ with whatever fits. (Perhaps CuteAsAButtonBuilder?)

    app/helpers/bootstrap_form_builder.rb

    class BootstrapFormBuilder < ActionView::Helpers::FormBuilder
        def button(label, options={})
    
        # You can also set default options, like a class
        default_class = options[:class] || 'btn'
        @template.button_tag(label.to_s.humanize, :class => default_class)    
      end
    
    end
    

    Now you have two ways to use the builder.

    1. DRY for ducks

    Every time you build a form that uses the button, you need to specify the builder…

    <%= form_for @duck, :builder => BootstrapFormBuilder do |form|%>
    

    2. DRY for devs

    Add the following

    app/helpers/application_helper.rb

    module ApplicationHelper
      def bootstrap_form_for(name, *args, &block)
        options = args.extract_options!
        form_for(name, *(args << options.merge(:builder => BootstrapFormBuilder)), &block)
      end
    end
    

    Just call the magic builder…

    <%= bootstrap_form_for @person do |form| %>
      <%= form.button 'Click Me' %>
    <% end %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sometimes when writing a class you'll need some helper methods that take care of
I know about SortedSet , but in my case I need something that implements
Similar to this Java question . I would like to specify that a variable
I have a form which will include some optional questions that need to asked
I have a helper class that implements ITypedList, to provide objects for databinding against
I have an object parameter and I need to check if the object implements
I need to implement some kind of metric space search in Postgres(*) (PL or
I am trying to write a Browser Helper Object (BHO) in C# that manipulates
I need to create a function that is only necessary inside one cshtml file.
I'm learning how to work with threads in Java and I need some advice..

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.