Browse files

Share idea on Fb after signature completion

  • Loading branch information...
1 parent 53eeae9 commit 8409ee355ac680daf686c44b884fd9495164c22d @RajRoR committed Dec 16, 2012
Showing with 41 additions and 2 deletions.
  1. +3 −1 app/controllers/signatures_controller.rb
  2. +3 −1 app/views/signatures/signing_success.html.haml
  3. +35 −0 lib/rack/lock.rb
View
4 app/controllers/signatures_controller.rb
@@ -919,14 +919,16 @@ def signing_success
session["authenticated_accept_publicity"] = @signature.accept_publicity
session["authenticated_accept_science"] = @signature.accept_science
+ @url = "#{request.protocol}#{request.host_with_port}"+"/ideat/"+"#{@signature.idea_id}"
+
# show only proposals that haven't yet been signed by current_citizen
signatures = Arel::Table.new(:signatures)
already_signed = Signature.where(signatures[:state].eq('signed'), signatures[:citizen].eq(current_citizen.id)).find(:all, select: "idea_id").map{|s| s.idea_id}.uniq
ideas = Arel::Table.new(:ideas)
proposals_not_in_already_signed = (ideas[:state].eq('proposal')).and(ideas[:id].not_in(already_signed))
proposals_collectible = (ideas[:collecting_in_service].eq(true)).and(ideas[:collecting_started].eq(true)).and(ideas[:collecting_ended].eq(false))
unsigned_collectible_proposals = proposals_not_in_already_signed.and(proposals_collectible)
- @initiatives = Idea.where(unsigned_collectible_proposals).order("vote_for_count DESC").limit(5).all
+ @initiatives = Idea.where(unsigned_collectible_proposals).order("vote_for_count DESC").limit(5).all
# Storing authenticated fileds inside profile for survey reporting
profile = current_citizen.profile
View
4 app/views/signatures/signing_success.html.haml
@@ -52,7 +52,7 @@
- if @signature.accept_science
.box
=survey_button("completed #{Signature.where(citizen_id: current_citizen.id).count} signature, #{@signature.idea} is the idea of latest signature", true)
-
+ <fb:share-button type="button_count" href="#{@url}">Share</fb:share-button>
- else
@@ -61,3 +61,5 @@
Virhe
= @error
=link_to "takaisin aloitteeseen", @signature.idea
+
+<script>(function(d, s, id) {var js, fjs = d.getElementsByTagName(s)[0];if (d.getElementById(id)) return;js = d.createElement(s); js.id = id;js.src = "//connect.facebook.net/en_US/all.js#xfbml=1"; // appId must be validfjs.parentNode.insertBefore(js, fjs);}(document, 'script', 'facebook-jssdk'));</script>
View
35 lib/rack/lock.rb
@@ -0,0 +1,35 @@
+require 'thread'
+
+module Rack
+ class Lock
+ FLAG = 'rack.multithread'.freeze
+
+ def initialize(app, mutex = Mutex.new)
+ @app, @mutex = app, mutex
+ end
+
+ def call(env)
+ old, env[FLAG] = env[FLAG], false
+
+ # Capture the mutex for the closure below
+ mutex = @mutex
+ mutex.lock
+ response = @app.call(env)
+ body = response[2]
+ should_super = body.respond_to?(:close)
+
+ body.extend Module.new {
+ define_method(:close) do
+ begin
+ super() if should_super
+ ensure
+ mutex.unlock
+ end
+ end
+ }
+ response
+ ensure
+ env[FLAG] = old
+ end
+ end
+end

0 comments on commit 8409ee3

Please sign in to comment.