Hoi,
I tried (and succeeded :-) to build a rails page where I can update objects by drag 'n drop. I show cards in a table and if they are dropped into a column an attribute is updated. So far so good, but unfortunately the update is not reflected in the card. I have to reload the whole site to see it (and yes, I use <%= ... :-) In the log I see, that the partial is rendered:
Started PUT "/cards/6" for 127.0.0.1 at 2013-03-21 16:55:42 +0100
Processing by CardsController#update as JS
Parameters: {"utf8"=>"✓", "authenticity_token"=>"B+xkdpwcIcslidgHQPh+I1n+Qh/MxltM=", "card"=>{"user_id"=>"2", "state_id"=>"1"}, "id"=>"6"}
Card Load (0.1ms) SELECT "cards".* FROM "cards" WHERE "cards"."id" = ? LIMIT 1 [["id", "6"]]
(0.1ms) begin transaction
(0.2ms) UPDATE "cards" SET "user_id" = 2, "updated_at" = '2013-03-21 15:55:42.630330' WHERE "cards"."id" = 6
(3.2ms) commit transaction
State Load (0.1ms) SELECT "states".* FROM "states" WHERE "states"."id" = ? LIMIT 1 [["id", 1]]
Rendered cards/_card.html.erb (2.8ms)
Completed 200 OK in 9ms (Views: 3.5ms | ActiveRecord: 3.8ms)
But in the Browser the user_id is still 3. So I tried to also show a notice:
format.js {render @card, notice: "nanu"}
But no success, the notice is not shown too.
My partial looks like this:
<%= form_for(@card, remote: true) do |f| %>
<div id="card_<%= @card.id %>" class="card_mini">
<h3><%= link_to @card.titel, edit_card_path(@card) %></h3>
<p><%= @card.beschreibung %></p>
<%= @card.user_id %> <!-- just to control the rendering -->
<%= f.text_field :user_id, type: "hidden" %>
<%= f.text_field :state_id, type: "hidden" %>
<div class="status"><%= @card.state_id ? State.find(@card.state_id).status : "--" %></div >
<%= link_to 'Destroy', @card, method: :delete, data: { confirm: 'Are you sure?' }, :class => "aktion" %>
</div>
<% end %>
Do you have any hints for me? Thanks, S.
Judging by comments you have to update DOM in your update.js.erb
. Smth like:
$("#<%= dom_id(@card) %>").append("<%=j render 'card/card', card: @card %>");