diff --git a/app/controllers/ideas_controller.rb b/app/controllers/ideas_controller.rb index 0a77db4..96bad41 100644 --- a/app/controllers/ideas_controller.rb +++ b/app/controllers/ideas_controller.rb @@ -27,9 +27,12 @@ def update end def participate - @user = User.find(params[:user_id]) - IdeaUser.create(:idea_id => @idea.id, :user_id => current_user.id) - @ideas = Idea.includes(:users) + if @idea.users.include?(current_user) + flash[:error] = 'You are already participating this idea' + else + @idea.users << current_user + end + redirect_to :action => :index end private diff --git a/app/views/ideas/index.html.haml b/app/views/ideas/index.html.haml index 4d06d22..977859f 100644 --- a/app/views/ideas/index.html.haml +++ b/app/views/ideas/index.html.haml @@ -6,7 +6,7 @@ %p= idea.description %h3 #{idea.users.count} Participating.... - unless idea.users.include?(current_user) - = link_to 'Participate', idea_participate_path(idea.id), :class => 'participate btn' + = link_to 'Participate', participate_idea_path(idea), :class => 'participate btn' :javascript $('.idea').click(function(){ window.location = $(this).attr('link') }) diff --git a/config/routes.rb b/config/routes.rb index 5dcb11f..dd2afea 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -8,11 +8,8 @@ match '/auth/failure' => 'services#failure' resources :ideas do - get 'participate' + get 'participate', :on => :member end - - match '/ideas/:id/participate/:user_id' => 'ideas#participate', :as => :participate - resources :schedules # used for the demo application only