Forum: Ruby on Rails how to prevent a newline after a button_to

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
78d56bb0f91c899d40f1767b3040d825?d=identicon&s=25 bingo bob (bingobob)
on 2009-01-29 10:27
How do you prevent a newline after a button_to.

I thought <%= button_to blabla -%> was meant to do it, but it didn't I
think I got it generated <div> tags around the button code.

How do you do it?

thanks
744b6438d1457d332d1a8d431cc2b641?d=identicon&s=25 Andrew Ohnstad (livitup)
on 2009-01-29 15:17
(Received via mailing list)
On Jan 29, 4:27 am, bingo bob <rails-mailing-l...@andreas-s.net>
wrote:
> How do you prevent a newline after a button_to.
>
> I thought <%= button_to blabla -%> was meant to do it, but it didn't I
> think I got it generated <div> tags around the button code.
>
> How do you do it?
>

This is something that gets tossed around from time to time.  The
official (barely) agreed upon stance is:

"The div is for HTML4.01/XHTML1.0 strict compliance. An input can only
be contained by one of "p", "h1", "h2", "h3", "h4", "h5", "h6", "div",
"pre", "address", "fieldset", "ins" or "del". "  [
http://dev.rubyonrails.org/ticket/10422
]

But this annoys me too.  There are a few ways of handling this.
button_to creates a form tag with a class of "button_to".  So in your
stylesheet, you should be able to do something
with .button_to .form .div and remove the spacing.  (I haven't tried
this myself yet, and I'm not a css whiz, so YMMV).

If you care less about strict compliance, and want to get rid of the
div tags totally, then the following in you application.rb will work:

module Helpers
    module UrlHelper
      def button_to(name, options = {}, html_options = nil)

        html_options = (html_options || {}).stringify_keys
        convert_boolean_attributes!(html_options, %w( disabled ))

        if confirm = html_options.delete("confirm")
          html_options["onclick"] = "return #
{confirm_javascript_function(confirm)};"
        end
        options = {:only_path=>false}.update(options)
        url = options.is_a?(String) ? options : url_for(options)
        name ||= url

        html_options.symbolize_keys!
        tag(:input, html_options.merge({
          :type => "button", :value => name,
          :onclick => (html_options[:onclick] ? "#{html_options
[:onclick]}; " : "") + "window.location.href='#{url_for(options)}';"
        }))

      end
    end
  end
This topic is locked and can not be replied to.