1

The button_to causes a line break before it in HTML. I have found a workaround which will work, but it's hardly ideal, because then the buttons are NOT real buttons. Is there any other way to avoid the line break before the form?

Here's the resulting HTML

<a href="/last_page">Back</a> | 
<form method="post" action="/next_page" class="button-to">
<div><input type="submit" value="Continue" /></div>
</form>

any help from the CSS side or the Rails side would really help!

7
  • Hi Mike. Thanks for your question. Rails makes it that way. It turns out the DIV is not the problem, the form is (at least in my testing). Commented Feb 11, 2009 at 2:32
  • Is it set to display: block ? Commented Feb 11, 2009 at 2:34
  • Alex, yeah, there it is, it's now inline-block and that works. Commented Feb 11, 2009 at 2:37
  • It has to be in a div according to HTML: putting an <input> directly inside <form> isn't valid. Commented Feb 11, 2009 at 2:55
  • wow, doesn't that make 50% of the web incorrect? Thanks for the comments everybody. Commented Feb 11, 2009 at 4:18

7 Answers 7

14

To only affect the button_to class and its inner div:

.button_to {
  display: inline;
}

.button_to div {
  display: inline;
}
Sign up to request clarification or add additional context in comments.

1 Comment

That's strange, I've seen that somewhere.
6

the button_to creates an HTML < form > element, which is a block element in HTML. If you give the form a class or id, you build your css selector to get the form and use:

form {
display: inline
}

1 Comment

thanks, Rails gives it a class automatically, so your solution works.
3

Ensure the CSS for that div is set to

display: inline;

Comments

3

Got it from somewhere out there. Happily:

.button-to { display:inline-block;}

Comments

2

None of these options worked for me on Rails 3.2.3 ! I found a working solution at http://www.deploymentzone.com/2011/12/07/button_to-urlhelpers-all-in-a-row/

Here it is:

/* ./app/assets/stylesheets/button_to.css.scss */

form.button_to {
    margin:0;
    padding:0;
    display:inline;
}

form.button_to div, form.button_to div input {
    display:inline;
}

Comments

0

You still have to specify inline for the div and the form.

div {
  display: inline;
}

.button-to {
  display: inline;
}

Wouldn't it be nicer if class="button-to" was also specified in the div ? or am I missing something ?

1 Comment

yes, otherwise you affect all your divs, which is definitely a problem-waiting-to-happen...
0

A button_to generates a form and a div around the button. So, if you do not restrict the width of the container which is before the button, it will take 100% of the width pushing the button down.

<% @post.bids.each do |bid| %>
  <p>
    <div style="float: left; width: auto;"><%= bid.user.email %></div>   
    <%= button_to "Offer Bid", offer_bid_post_bid_path(@post, bid), :action => "offer_bid" %>
  </p>
<% end %>

1 Comment

That's a good explanation of the problem, but doesn't offer a specific solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.