From e70f95d7a424f760ec14903601ad5ede59e541d1 Mon Sep 17 00:00:00 2001 From: Rishi Jain Date: Mon, 28 May 2012 11:55:24 +0530 Subject: [PATCH 1/3] added "not interested" link once user clicks on interested updated the count of participants as user clicks on interested/not interested --- app/controllers/ideas_controller.rb | 7 ++++++- app/views/ideas/_idea.html.haml | 9 +++++++-- app/views/ideas/_link_for_participate.html.haml | 2 ++ app/views/ideas/_link_for_un_participate.html.haml | 3 +++ app/views/ideas/_participants_count.html.haml | 2 ++ app/views/ideas/not_interested.js.haml | 4 ++++ app/views/ideas/participate.js.haml | 5 ++++- config/routes.rb | 1 + db/schema.rb | 2 +- 9 files changed, 30 insertions(+), 5 deletions(-) create mode 100644 app/views/ideas/_link_for_participate.html.haml create mode 100644 app/views/ideas/_link_for_un_participate.html.haml create mode 100644 app/views/ideas/_participants_count.html.haml create mode 100644 app/views/ideas/not_interested.js.haml diff --git a/app/controllers/ideas_controller.rb b/app/controllers/ideas_controller.rb index 9e6fd99..893043c 100644 --- a/app/controllers/ideas_controller.rb +++ b/app/controllers/ideas_controller.rb @@ -1,6 +1,6 @@ class IdeasController < ApplicationController before_filter :authenticate_user!, :except => [:index, :show] - before_filter :get_idea, :only => [:update, :edit, :show, :participate] + before_filter :get_idea, :only => [:update, :edit, :show, :participate, :not_interested] def show redirect_to ideas_path @@ -47,6 +47,11 @@ def participate end end + def not_interested + idea_user = IdeaUser.where(:user_id => current_user.id, :idea_id => @idea.id).first + idea_user.destroy unless idea_user.nil? + end + private def get_idea @idea = Idea.find_by_id(params[:id]) diff --git a/app/views/ideas/_idea.html.haml b/app/views/ideas/_idea.html.haml index 814e776..63ef7ae 100644 --- a/app/views/ideas/_idea.html.haml +++ b/app/views/ideas/_idea.html.haml @@ -7,7 +7,11 @@ %span= raw idea.description.truncate(200) = link_to 'Details', "#idea-detail-#{idea.id}", class: 'details btn btn-info', data: {toggle: 'modal'} - unless idea.users.include?(current_user) - = link_to 'Participate', participate_idea_path(idea), :class => 'participate btn btn-info', :remote => true + %div{:id => "add_not_interested_link_#{idea.id}"} + = link_to 'Participate', participate_idea_path(idea), :class => 'participate btn btn-info', :id => "participate_#{idea.id}", :remote => true + - else + %div{:id => "add_participate_link_#{idea.id}"} + = link_to 'Not Interested', not_interested_idea_path(idea), :class => 'participate btn btn-info', :id => "not_interested_#{idea.id}", :remote => true %span.detail %span %i.icon-calendar> @@ -15,7 +19,8 @@ | %span %i.icon-user> - = pluralize(idea.users.count, "participant") + %span{:id => "participants_count_#{idea.id}"} + = pluralize(idea.users.count, "participant") .modal{style: "display:none", id: "idea-detail-#{idea.id}"} .modal-header diff --git a/app/views/ideas/_link_for_participate.html.haml b/app/views/ideas/_link_for_participate.html.haml new file mode 100644 index 0000000..ea33531 --- /dev/null +++ b/app/views/ideas/_link_for_participate.html.haml @@ -0,0 +1,2 @@ +%div{:id => "add_not_interested_link_#{@idea.id}"} + = link_to 'Participate', participate_idea_path(@idea), :class => 'participate btn btn-info', :id => "participate_#{@idea.id}", :remote => true diff --git a/app/views/ideas/_link_for_un_participate.html.haml b/app/views/ideas/_link_for_un_participate.html.haml new file mode 100644 index 0000000..ee3d8a2 --- /dev/null +++ b/app/views/ideas/_link_for_un_participate.html.haml @@ -0,0 +1,3 @@ +%div{:id => "add_participate_link_#{@idea.id}"} + = link_to 'Not Interested', not_interested_idea_path(@idea), :class => 'participate btn btn-info', :id => "not_interested_#{@idea.id}", :remote => true + diff --git a/app/views/ideas/_participants_count.html.haml b/app/views/ideas/_participants_count.html.haml new file mode 100644 index 0000000..79c210e --- /dev/null +++ b/app/views/ideas/_participants_count.html.haml @@ -0,0 +1,2 @@ +%span{:id => "participants_count_#{@idea.id}"} + = pluralize(@idea.users.count, "participant") diff --git a/app/views/ideas/not_interested.js.haml b/app/views/ideas/not_interested.js.haml new file mode 100644 index 0000000..f36817d --- /dev/null +++ b/app/views/ideas/not_interested.js.haml @@ -0,0 +1,4 @@ +$('#idea-#{@idea.id} a h2 i').removeClass('favorite') +$('#add_participate_link_#{@idea.id}').html("#{escape_javascript(render :partial => 'ideas/link_for_participate')}") +$('#participants_count_#{@idea.id}').html("#{escape_javascript(render :partial => 'ideas/participants_count')}") + diff --git a/app/views/ideas/participate.js.haml b/app/views/ideas/participate.js.haml index 35f4537..738c5dd 100644 --- a/app/views/ideas/participate.js.haml +++ b/app/views/ideas/participate.js.haml @@ -1,3 +1,6 @@ +$('#idea-#{@idea.id} h3').text("#{pluralize(@idea.users.count, "participant")}") $('#idea-#{@idea.id} a h2 i').addClass('favorite') $('#idea-#{@idea.id} a.participate.btn').remove() -$('#idea-#{@idea.id} h3').html("#{pluralize(@idea.users.count, "participant")}") +$('#add_not_interested_link_#{@idea.id}').html("#{escape_javascript(render :partial => 'ideas/link_for_un_participate')}") +$('#participants_count_#{@idea.id}').html("#{escape_javascript(render :partial => 'ideas/participants_count')}") + diff --git a/config/routes.rb b/config/routes.rb index 07cfbdb..0d90326 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -18,6 +18,7 @@ resources :ideas do get 'participate', :on => :member + get 'not_interested', :on => :member resources :schedules end diff --git a/db/schema.rb b/db/schema.rb index f71c2c9..cbf33f0 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20120521112817) do +ActiveRecord::Schema.define(:version => 20120521120228) do create_table "categories", :force => true do |t| t.string "name" From de6d46671e3655df114df2cde8bf5aa68e3199bd Mon Sep 17 00:00:00 2001 From: Rishi Jain Date: Fri, 22 Jun 2012 19:18:27 +0530 Subject: [PATCH 2/3] removed earlier code --- app/controllers/ideas_controller.rb | 7 +------ app/views/ideas/_link_for_participate.html.haml | 2 -- app/views/ideas/_link_for_un_participate.html.haml | 3 --- app/views/ideas/_participants_count.html.haml | 2 -- app/views/ideas/not_interested.js.haml | 4 ---- config/routes.rb | 1 - 6 files changed, 1 insertion(+), 18 deletions(-) delete mode 100644 app/views/ideas/_link_for_participate.html.haml delete mode 100644 app/views/ideas/_link_for_un_participate.html.haml delete mode 100644 app/views/ideas/_participants_count.html.haml delete mode 100644 app/views/ideas/not_interested.js.haml diff --git a/app/controllers/ideas_controller.rb b/app/controllers/ideas_controller.rb index dbb549e..5b19dc2 100644 --- a/app/controllers/ideas_controller.rb +++ b/app/controllers/ideas_controller.rb @@ -1,6 +1,6 @@ class IdeasController < ApplicationController before_filter :authenticate_user!, :except => [:index, :show] - before_filter :get_idea, :only => [:update, :edit, :show, :participate, :not_interested] + before_filter :get_idea, :only => [:update, :edit, :show, :participate] def index @ideas = Idea.includes(:users).includes(:categories) @@ -48,11 +48,6 @@ def participate end end - def not_interested - idea_user = IdeaUser.where(:user_id => current_user.id, :idea_id => @idea.id).first - idea_user.destroy unless idea_user.nil? - end - private def get_idea @idea = Idea.find_by_id(params[:id]) diff --git a/app/views/ideas/_link_for_participate.html.haml b/app/views/ideas/_link_for_participate.html.haml deleted file mode 100644 index ea33531..0000000 --- a/app/views/ideas/_link_for_participate.html.haml +++ /dev/null @@ -1,2 +0,0 @@ -%div{:id => "add_not_interested_link_#{@idea.id}"} - = link_to 'Participate', participate_idea_path(@idea), :class => 'participate btn btn-info', :id => "participate_#{@idea.id}", :remote => true diff --git a/app/views/ideas/_link_for_un_participate.html.haml b/app/views/ideas/_link_for_un_participate.html.haml deleted file mode 100644 index ee3d8a2..0000000 --- a/app/views/ideas/_link_for_un_participate.html.haml +++ /dev/null @@ -1,3 +0,0 @@ -%div{:id => "add_participate_link_#{@idea.id}"} - = link_to 'Not Interested', not_interested_idea_path(@idea), :class => 'participate btn btn-info', :id => "not_interested_#{@idea.id}", :remote => true - diff --git a/app/views/ideas/_participants_count.html.haml b/app/views/ideas/_participants_count.html.haml deleted file mode 100644 index 79c210e..0000000 --- a/app/views/ideas/_participants_count.html.haml +++ /dev/null @@ -1,2 +0,0 @@ -%span{:id => "participants_count_#{@idea.id}"} - = pluralize(@idea.users.count, "participant") diff --git a/app/views/ideas/not_interested.js.haml b/app/views/ideas/not_interested.js.haml deleted file mode 100644 index f36817d..0000000 --- a/app/views/ideas/not_interested.js.haml +++ /dev/null @@ -1,4 +0,0 @@ -$('#idea-#{@idea.id} a h2 i').removeClass('favorite') -$('#add_participate_link_#{@idea.id}').html("#{escape_javascript(render :partial => 'ideas/link_for_participate')}") -$('#participants_count_#{@idea.id}').html("#{escape_javascript(render :partial => 'ideas/participants_count')}") - diff --git a/config/routes.rb b/config/routes.rb index 0d90326..07cfbdb 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -18,7 +18,6 @@ resources :ideas do get 'participate', :on => :member - get 'not_interested', :on => :member resources :schedules end From 52dd0d13e3f7d8b59b6922d342ecf0127b78d471 Mon Sep 17 00:00:00 2001 From: Rishi Jain Date: Fri, 22 Jun 2012 20:04:39 +0530 Subject: [PATCH 3/3] fixed the count of users --- app/views/ideas/_idea.html.haml | 2 +- app/views/ideas/participate.js.haml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/ideas/_idea.html.haml b/app/views/ideas/_idea.html.haml index d39c996..0d3b9cb 100644 --- a/app/views/ideas/_idea.html.haml +++ b/app/views/ideas/_idea.html.haml @@ -16,7 +16,7 @@ .floatLeft %i.icon-user> =# pluralize(idea.users.count, "participant") - = idea.users.count + %span{:id => "idea_count_#{idea.id}"} #{idea.users.count} .floatRight = tweet_button :via => "punerb",:count=> "none", :url => idea_url(idea), :text => "This is an interesting idea! Help out " diff --git a/app/views/ideas/participate.js.haml b/app/views/ideas/participate.js.haml index 2dba9d2..4a9a33a 100644 --- a/app/views/ideas/participate.js.haml +++ b/app/views/ideas/participate.js.haml @@ -1,4 +1,4 @@ -$('#idea-#{@idea.id} .detail span:last').html(" #{pluralize(@idea.users.count, 'participant')}") +$('#idea_count_#{@idea.id}').text("#{@idea.users.count}") - if @participant $('#idea-#{@idea.id} a.participate.btn').text('Participate') $('#idea-#{@idea.id} a h2 i').removeClass('favorite')