Search code examples
ruby-on-railscssruby-on-rails-3view

Rails: How to make "button_to" button to appear on the sameline (without a newline)?


I have a block iterator to display a user and a related action to be displayed on the same line for every iteration.

You can visualize it like this:

user1  update_attribute_button
user2  update_attribute_button.
...
and so on.

If I use a button_to method the button is getting displayed on a newline. which I don't want.

Here is my code snippet:

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

But with the above code the 'email' and 'offer bid' appear on two separate lines, but I want to display them both on the same line.

If I use link_to instead of button_to I'm able to achieve my idea, but not able to do it with a button_to. What is the difference between link_to and button_to?
I want to display the 'offer bid' as a button only.
How do I make the button_to button appear on the same line as the 'email'?

Please let me know if the question's description is not clear. Thanks in advance.


Solution

  • 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 %>