Permalink
Browse files

participate idea

  • Loading branch information...
1 parent 4b0be4e commit 6c1a1b05e08199b86193a94cab906ef24044e288 Sandip Ransing committed Apr 27, 2012
Showing with 8 additions and 8 deletions.
  1. +6 −3 app/controllers/ideas_controller.rb
  2. +1 −1 app/views/ideas/index.html.haml
  3. +1 −4 config/routes.rb
View
9 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
View
2 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') })
View
5 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

0 comments on commit 6c1a1b0

Please sign in to comment.