Ruby-on-Rails [SOLVED]: Style rails button_to

Ruby-on-Rails [SOLVED]: Style rails button_to

Home Forums Frameworks Ruby on Rails Tutorials Ruby-on-Rails [SOLVED]: Style rails button_to

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #246764

    Cloudy Point
    Keymaster

    QuestionQuestion

    I have a button:

    <%= button_to "Unsubscribe",  cancel_subscription_path, method: :post, data: { confirm: "Are you sure?" } %>
    

    and am trying to add styles to this button.

    I tried

    <%= button_to "Unsubscribe",  cancel_subscription_path, method: :post, data: { confirm: "Are you sure?" }, {class:"myClass"} %>
    

    and

    <%= button_to "Unsubscribe",  {cancel_subscription_path, method: :post, data: { confirm: "Are you sure?" }}, {class:"myClass"} %>
    

    #246765

    Cloudy Point
    Keymaster

    Accepted AnswerAnswer

    I think this will work for you

    <%= button_to "Unsubscribe", root_path, method: :post, data: { confirm: "Are you sure?" }, class:"myClass" %>
    

    It will generate form like this

    <form class="button_to" method="post" action="/">
      <input data-confirm="Are you sure?" class="myClass" type="submit" value="Unsubscribe">
      <input type="hidden" name="authenticity_token" value="ViECdS4KxrTfhazHRcx/6uUp+VXYUUUrqIMNX7jCz24cpeIEcY41IGDAHU1KLOYp2RuwNidxyIKHRlZubUU61SLA==">
    </form>
    

    For more details have a look at the examples section here.

    Source: https://stackoverflow.com/questions/47966824/style-rails-button-to
    Author: Manishh
    Creative Commons License
    This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.