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 8415863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:34:14+00:00 2026-06-10T01:34:14+00:00

Possible Duplicate: Is there a way with rails form helper to produce a button

  • 0

Possible Duplicate:
Is there a way with rails form helper to produce a button tag for submit

This is probably quite an easy question, but I’ve got this HTML layout:

<button class="btn btn-large btn-inverse"><i class="icon-white icon-shopping-cart"></i> Add to bag</button> 

This is an add to cart button, I’m following along the book Agile Web Development to create a cart. Question is, with embedded HTML between the button tag, how do I get it to render like that? I tried this:

%= button_to raw('<i class="icon-white icon-shopping-cart"></i> Add to bag'), line_items_path(product_id: product) %>

But firstly it prints an “input” not a button, and the text is all askew in the html and not between opening and closing tags.

I know I can just write it all manually, but was hoping to figure out if there’s a shortcut way to do this HTML to output using the rails tags, mainly because with twitter bootstrap I see this type of HTML pattern all the time…

Any help is appreciated.

  • 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-06-10T01:34:16+00:00Added an answer on June 10, 2026 at 1:34 am

    As commented by Mischa, it is similar to Is there a way with rails form helper to produce a button tag for submit.

    The content_tag helper can be used to write the button in rails. However, it is not a shortcut, since it will take longer to write than the raw html.

    However, if you need to do this often, you can write a custom helper method to do it the way you want!

    Just add to your app/helpers/application_helper.rb

    def my_button_to name, options = {}, html_options = {} # or some variation
      # eg. deal with options hash the way button_to deals with it here?
      content_tag :button, html_options = nil do
        raw name
      end
    end
    

    Now you can use this in your views:

    <%= my_button_to '<i class="icon-white icon-shopping-cart"></i> Add to bag', {}, :class => "btn btn-large btn-inverse" %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Is there an easy way in .NET to get “st”, “nd”, “rd”
Possible Duplicate: Is there an easy way to convert a number to a word
Possible Duplicate: Is there a way to catch the back button event in javascript?
Possible Duplicate: Is there an easy way to change the color of a bullet
Possible Duplicate: Android Button Tooltip Is there any way to construct a view where
Possible Duplicate: Image Button in BlackBerry Is there a way to have a picture
Possible Duplicate: Is there any way to kill a Thread in Python? So this
Possible Duplicate: Is there a simpler way to do this if statement in C#
Possible Duplicate: Is there a way of drawing a caption box in matplotlib Is
Possible Duplicate: Is there any way to determine text direction from CultureInfo in asp.net?

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.