Skip to content

Commit

Permalink
participate idea
Browse files Browse the repository at this point in the history
  • Loading branch information
Sandip Ransing committed Apr 27, 2012
1 parent 4b0be4e commit 6c1a1b0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
9 changes: 6 additions & 3 deletions app/controllers/ideas_controller.rb
Expand Up @@ -27,9 +27,12 @@ def update
end end


def participate def participate
@user = User.find(params[:user_id]) if @idea.users.include?(current_user)
IdeaUser.create(:idea_id => @idea.id, :user_id => current_user.id) flash[:error] = 'You are already participating this idea'
@ideas = Idea.includes(:users) else
@idea.users << current_user
end
redirect_to :action => :index
end end


private private
Expand Down
2 changes: 1 addition & 1 deletion app/views/ideas/index.html.haml
Expand Up @@ -6,7 +6,7 @@
%p= idea.description %p= idea.description
%h3 #{idea.users.count} Participating.... %h3 #{idea.users.count} Participating....
- unless idea.users.include?(current_user) - 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 :javascript
$('.idea').click(function(){ window.location = $(this).attr('link') }) $('.idea').click(function(){ window.location = $(this).attr('link') })
5 changes: 1 addition & 4 deletions config/routes.rb
Expand Up @@ -8,11 +8,8 @@
match '/auth/failure' => 'services#failure' match '/auth/failure' => 'services#failure'


resources :ideas do resources :ideas do
get 'participate' get 'participate', :on => :member
end end

match '/ideas/:id/participate/:user_id' => 'ideas#participate', :as => :participate

resources :schedules resources :schedules


# used for the demo application only # used for the demo application only
Expand Down

0 comments on commit 6c1a1b0

Please sign in to comment.