Skip to content

Instantly share code, notes, and snippets.

@kmelkon
Last active December 21, 2015 17:18
Show Gist options
  • Save kmelkon/6339271 to your computer and use it in GitHub Desktop.
Save kmelkon/6339271 to your computer and use it in GitHub Desktop.
<address>
<%= deal.value %><br>
<%= deal.background %><br>
</address>
<div class="no-radio">
<div class="btn-group" data-toggle="buttons-radio">
<%= form_tag status_deal_path(deal), :remote => true, :class => "deals_status" do %>
<%= radio_button_tag :state, "won"+deal.id.to_s, deal.state == "won", :class => "toggle-btn-left toggle-btn", :value =>"won" %>
<%= label_tag 'state_won'+deal.id.to_s, "won", :class=>"btn" %>
<%= radio_button_tag :state, "lost"+deal.id.to_s, deal.state == 'lost', :class => "toggle-btn-center toggle-btn",:value => "lost" %>
<%= label_tag 'state_lost'+deal.id.to_s, "lost",:class=>"btn" %>
<%= radio_button_tag :state, "pending"+deal.id.to_s, deal.state == 'pending',:class => "toggle-btn-right toggle-btn", :value => "pending" %>
<%= label_tag 'state_pending'+deal.id.to_s, "pending", :class=>"btn" %>
<% end %>
</div>
</div>
$("body").on("change", "form :radio", function(){
$(this).closest("form").submit();
});
$('.deals-wrapper').append('<%= escape_javascript(render :partial => "deals/deal", :locals => {:deal => @deal}) %>');
Started POST "/companies/31/deals" for 127.0.0.1 at 2013-08-26 11:29:50 +0300
Processing by DealsController#create as JS
Parameters: {"utf8"=>"✓", "authenticity_token"=>"Nhflt/o9HdfsWXpsSaKddd5yvItOsGtDoFD5N/Rbfns=", "deal"=>{"name"=>"", "value"=>"", "currency"=>"", "background"=>"w"}, "commit"=>"Add this Deal", "company_id"=>"31"}
Company Load (0.2ms) SELECT "companies".* FROM "companies" WHERE "companies"."id" = 31 LIMIT 1
(0.1ms) begin transaction
SQL (0.6ms) INSERT INTO "deals" ("background", "company_id", "created_at", "currency", "deal_category_id", "deal_status_id", "name", "offer", "state", "status", "updated_at", "user_id", "value") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) [["background", "w"], ["company_id", 31], ["created_at", Mon, 26 Aug 2013 08:29:50 UTC +00:00], ["currency", ""], ["deal_category_id", nil], ["deal_status_id", nil], ["name", ""], ["offer", nil], ["state", nil], ["status", nil], ["updated_at", Mon, 26 Aug 2013 08:29:50 UTC +00:00], ["user_id", nil], ["value", nil]]
(167.5ms) commit transaction
Rendered deals/_deal.html.erb (1.2ms)
Rendered deals/create.js.erb (35.1ms)
Completed 200 OK in 220ms (Views: 40.8ms | ActiveRecord: 168.4ms)
def status
@deal = Deal.find_by_id(params[:id])
@deal.update_attribute(:state, params[:state])
respond_to do |format|
format.js
end
end
$('.deals-wrapper').append('<address>\n <br>\n test<br> \n<\/address>\n\n<div class=\"no-radio\">\n <div class=\"btn-group\" data-toggle=\"buttons-radio\">\n\n <form accept-charset=\"UTF-8\" action=\"/deals/101/status\" class=\"deals_status\" data-remote=\"true\" method=\"post\"><div style=\"margin:0;padding:0;display:inline\"><input name=\"utf8\" type=\"hidden\" value=\"&#x2713;\" /><input name=\"authenticity_token\" type=\"hidden\" value=\"Nhflt/o9HdfsWXpsSaKddd5yvItOsGtDoFD5N/Rbfns=\" /><\/div>\n <input class=\"toggle-btn-left toggle-btn\" id=\"state_won101\" name=\"state\" type=\"radio\" value=\"won\" />\n <label class=\"btn\" for=\"state_won101\">won<\/label> \n \n <input class=\"toggle-btn-center toggle-btn\" id=\"state_lost101\" name=\"state\" type=\"radio\" value=\"lost\" />\n <label class=\"btn\" for=\"state_lost101\">lost<\/label>\n \n <input class=\"toggle-btn-right toggle-btn\" id=\"state_pending101\" name=\"state\" type=\"radio\" value=\"pending\" />\n <label class=\"btn\" for=\"state_pending101\">pending<\/label>\n<\/form><\/div>\n<\/div>\n');
<address>
12.0<br>
test<br>
</address>
<div class="no-radio">
<div class="btn-group" data-toggle="buttons-radio">
<form accept-charset="UTF-8" action="/deals/99/status" class="deals_status" data-remote="true" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value=""><input name="authenticity_token" type="hidden" value=""></div>
<input class="toggle-btn-left toggle-btn" id="state_won99" name="state" type="radio" value="">
<label class="btn" for="state_won99">won</label>
<input class="toggle-btn-center toggle-btn" id="state_lost99" name="state" type="radio" value="">
<label class="btn" for="state_lost99">lost</label>
<input class="toggle-btn-right toggle-btn" id="state_pending99" name="state" type="radio" value="">
<label class="btn" for="state_pending99">pending</label>
</form></div>
</div>
Started POST "/deals/96/status" for 127.0.0.1 at 2013-08-26 11:31:01 +0300
Processing by DealsController#status as JS
Parameters: {"utf8"=>"", "authenticity_token"=>"", "state"=>"", "id"=>"96"}
Deal Load (0.3ms) SELECT "deals".* FROM "deals" WHERE "deals"."id" = 96 LIMIT 1
(0.1ms) begin transaction
(0.3ms) UPDATE "deals" SET "state" = '', "updated_at" = '2013-08-26 08:31:01.718168' WHERE "deals"."id" = 96
(236.8ms) commit transaction
Rendered deals/status.js.erb (0.1ms)
Completed 200 OK in 249ms (Views: 5.7ms | ActiveRecord: 237.5ms)
<% @deals.each do |deal| %>
<%= render :partial => 'deals/deal', :locals => {:deal => deal} %>
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment