Search code examples
ruby-on-railsrubyhamllink-tobutton-to

rails, view does line feed for button_to but not link_to


%p
  %br
  %span.footer_links
    = link_to 'Edit', edit_link_path(@link)
    = link_to 'Edit', edit_link_path(@link)
    = button_to 'Delete', @link, :confirm => 'Are you sure?', :method => :delete
    = button_to 'Delete', @link, :confirm => 'Are you sure?', :method => :delete
    pppppp

Produces "edit" links on the same line but delete buttons on different lines, e.g.

      edit  edit
      delete
      delete

(two of each for emphasis about line breaks)

How can I get all the above on 1 line as in:

edit edit [delete] [delete]

I am doing this becuase I need to change my link_to, :method => :delete to :button_to's

Update: I added, :class => '.btn' to my button_to with .btn { display: inline; } in my css but it hasn't helped.

<p>
<br/>
<span class="footer_links">
<a href="/links/354/edit">Edit</a>
 | 
</span>
</p>
<form method="post" action="/links/354" class="button_to">
<div>
<input name="_method" type="hidden" value="delete"/>
<input class=".btn" data-confirm="Are you sure?" type="submit" value="Delete"/>
<input name="authenticity_token" type="hidden" value="MvN6K03y5WcqSZRt4Au3zj+xsKhfZ9EEtkf2M7YCGhk="/>
</div>
</form>
<p/>

Solution

  • Strange, because both the a generated by link_to and the input generated by button_to should be inline elements.

    This is exactly what CSS is for, though: keeping design details out of the HTML. So you could have CSS like this:

    .footer_links a, .footer_links input {
      display: inline;
      padding-right: 1em;
    }
    

    [Useful edit - also from Buck - You can use :form_class and then style the form and the div inside it as inline. ]