0

I have this content in a html.erb file. The file is referred to from some view files with render.

<table>
<tr>
    <th>image</th>
    <th>name</th>
    <th>description</th>
    <th>status</th>
    <th>Options</th>
</tr>

<% @activities.each do |activity| %>
    <% if activity.in? @activities_completed then next; end %> 
        <tr>
            <td><%= image_tag activity.photo.url(:thumb) %></td>
            <td><%= activity.name %></td>
            <td><%= activity.description %></td>
            <td><%= (activity.in?(@activities_gotten)) ? (image_tag "pending_activity.png") : (image_tag "missing_activity.png") %></td>
            <td>
                <% if activity.in? @activities_gotten %>
                    <%= button_to 'Remove', {:controller => :bucket_items, :action => :remove, :id => activity.id} %>
                <% else %>
                    <%= button_to 'Add', {:controller => :bucket_items, :action => :add, :id => activity.id} %> 
                <% end %>
                <%= button_to 'Show', activity , :method => :get %>
            </td>
        </tr>
    <% end %>
</table>

the td with the buttons in the first iteration of the .each is rendered as:

<td>
<div>
    <input type="submit" value="Add">
    <input name="authenticity_token" type="hidden" value="KyR2ftDGxNti7bZ2zpW/V+UGYUbHpZ+efxX4h48a6L0=">
</div> 
<form action="/activities/10" class="button_to" method="get">
    <div>
        <input type="submit" value="Show">
    </div>
</form>
</td>

While the second and all the others:

<td>
<form action="/bucket_items/remove?id=13" class="button_to" method="post">
    <div>
        <input type="submit" value="Remove">
        <input name="authenticity_token" type="hidden" value="KyR2ftDGxNti7bZ2zpW/V+UGYUbHpZ+efxX4h48a6L0=">
    </div>
</form>
<form action="/activities/13" class="button_to" method="get">
    <div>
        <input type="submit" value="Show">
    </div>
</form>
</td>

There's obviously a problem somewhere, as the first button won't work (obviously, there's no form tag around it), and that is the only one not working.

Any clue about what's happening here?

thanks,

Don Giulio
  • 2,946
  • 3
  • 43
  • 82

1 Answers1

1

I figured:

the erb I posted is the content of a partial, that is rendered from the actual view file.

The render command was contained already in a form_for function, therefore this was confusing Rails and giving the odd result.

solved,

thanks,

Don Giulio
  • 2,946
  • 3
  • 43
  • 82
  • What did you do to fix it though? – Elijah Murray Jan 14 '14 at 06:19
  • 1
    well, the fact that I was calling the partial from within a `
    `, and that the partial itself contained a `
    ` tag meant that the html generated was malformed, as you can't have nested forms, so I just fixed the double `form` by removing one of them. If I remember well I removed the one that was in the view that was calling the partial. so I left the form only in the partial.
    – Don Giulio Jan 14 '14 at 15:59