Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Leave Magazine #111

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .DS_Store
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions app/controllers/magazines_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,19 @@ def error
render json: @magazine.errors, status: :unprocessable_entity
end
end
# Author:Andrew
# 2.5.2015
# Removes User From Magazine
def leave
@magazine = Magazine.find(params[:m_id])
@user = current_user
@magazine.users.delete(@user)
@user.magazines.delete(@magazine)
@user.save
@magazine.save
redirect_to :back

end

# POST /magazines
# POST /magazines.json
Expand Down
4 changes: 4 additions & 0 deletions app/models/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ def initialize(user)
can :update, Magazine do |m|
(m.users.include? user)
end

can :leave, Magazine do |m|
(m.users.first != user)
end
# 5.4.2015
# check promote if current user
# and not promoted before
Expand Down
1 change: 0 additions & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ class User < ActiveRecord::Base
has_many :ads, dependent: :destroy
has_and_belongs_to_many :magazines
has_many :collaboration_invitation
has_many :magazines, through: :collaboration_invitation
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
#:recoverable,
Expand Down
6 changes: 6 additions & 0 deletions app/views/magazines/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@
</div>
<div class="modal-body">
<% @users.each do |u| %>

<% if current_user.id == u.id %>
<% if can? :leave , @magazine %>
<%= link_to '<span style = "color: red" class="fa fa-trash"></span>'.html_safe,controller: :magazines, action: :leave, m_id: @magazine.id %>
<% end %>
<% end %>
<!-- change to link_to u.firstname, u -->
<img style="width: 50px; height: 50px;"src = "<%= u.avatar %>" alt="<%= u.firstname %>"/>
<a href ="#"> <%= u.firstname %></a>
Expand Down
7 changes: 6 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

resources :ads
resources :articles
resources :magazines
resources :comments
resources :replies

Expand All @@ -22,6 +21,12 @@
end
end

resources :magazines do
collection do
get 'leave'
end
end

resources :bids do
collection do
get 'destroy'
Expand Down
2 changes: 1 addition & 1 deletion coverage/.last_run.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"result": {
"covered_percent": 81.03
"covered_percent": 81.65
}
}
Loading