Skip to content

Commit

Permalink
#61 almost done
Browse files Browse the repository at this point in the history
  • Loading branch information
MinaHany94 committed Apr 7, 2015
1 parent 56bb7e7 commit 732edf5
Show file tree
Hide file tree
Showing 14 changed files with 10,503 additions and 51 deletions.
22 changes: 21 additions & 1 deletion app/controllers/magazines_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,32 @@ def check_for_cancel

# Request joining a magazine
def join
joinh = { "user_id" => current_user.id, "magazine_id" => params[:id] }
joinh = { 'user_id' => current_user.id, 'magazine_id' => params[:id] }
Requestjoiningmagazine.create(joinh)
@magazine = Magazine.find(params[:id])
redirect_to @magazine
end

def showrequests
@request = Requestjoiningmagazine.where('magazine_id = ?', params[:id])
@users = []
@request.each do |r|
@users.push(User.find(r.user_id))
end
end

def approverequest
@req = Requestjoiningmagazine.where("user_id = ? AND magazine_id = ?", params[:user], params[:id])
@req.destroy_all
joinh = { 'user_id' => params[:user], 'magazine_id' => params[:id] }
Requestjoiningmagazine.destroy_all(joinh)

@magazine = Magazine.find(params[:id])
@user = User.find(params[:user])
@magazine.users << @user
redirect_to :action => :showrequests
end

private

# Use callbacks to share common setup or constraints between actions.
Expand Down
2 changes: 2 additions & 0 deletions app/models/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ def initialize(user)
can :create, Magazine
can :update, Magazine
can :join, Magazine
can :showrequests, Magazine
can :approverequest, Magazine
can :update, Comment do |c|
c.user_id == user.id
end
Expand Down
4 changes: 0 additions & 4 deletions app/models/joinmagazine.rb

This file was deleted.

2 changes: 0 additions & 2 deletions app/models/magazine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
# 5.4.2015
# Magazines model
class Magazine < ActiveRecord::Base
has_many :joinmagazines
has_many :magazines, through: :joinmagazines
# many-to-many relationship between magazine
# requested to join to by many users
has_many :requestjoiningmagazines
Expand Down
3 changes: 0 additions & 3 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# User Model
class User < ActiveRecord::Base
has_many :joinmagazines
has_many :magazines, through: :joinmagazines

# many-to-many relationship between user requests joining magazine
has_many :requestjoiningmagazines
has_many :magazines, through: :requestjoiningmagazines
Expand Down
2 changes: 1 addition & 1 deletion app/views/magazines/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@
<%= link_to 'Back', magazines_path %> |
<! link to request joining magazine>
<%= link_to 'Join this magazine', action: "join" %> |
<%= link_to 'View joining requests', {:controller => 'magazinesjoin', :action => 'index', :magazine => @magazine.id }%>
<%= link_to 'View joining requests', action: 'showrequests'%>
37 changes: 37 additions & 0 deletions app/views/magazines/showrequests.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<div class="editor" >
<h1>Joining requests</h1>

<div class="row">
<div class="col-sm-3 ">
Name
</div>
<div class="col-sm-3 ">
email
</div>
</div>

<% @users.each do |user| %>

<div class="row">
<div class="col-sm-3 ">
<%= user.firstname %> &nbsp;<%= user.lastname %>
</div>
<div class="col-sm-3 ">
<%= user.email %>
</div>

<div class="col-sm-3 ">
<%= link_to 'Approve', {:action => "approverequest", :user => user.id } %>
</div>

<div class="col-sm-3 ">
<%= link_to 'Reject', sponsors_path(@s,:type =>"Reject") %>
</div>
</div>
<%end%>
<% if @users.size == 0 %>
<em>No Joining requests are found</em>
<% end %>


</div>
11 changes: 10 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
Rails.application.routes.draw do
resources :magazines
resources :magazinesjoin
resources :magazines do
member do
get 'join'
end
end
resources :magazines do
member do
get 'showrequests'
end
end
resources :magazines do
member do
get 'approverequest'
end
end

# adding resources
resources :sponsors
Expand Down
Binary file modified db/development.sqlite3
Binary file not shown.
12 changes: 0 additions & 12 deletions db/migrate/20150407103735_create_joinmagazines.rb

This file was deleted.

12 changes: 1 addition & 11 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20150407103735) do
ActiveRecord::Schema.define(version: 20150406201640) do

create_table "articles", force: :cascade do |t|
t.string "title"
Expand All @@ -31,16 +31,6 @@
t.datetime "updated_at", null: false
end

create_table "joinmagazines", force: :cascade do |t|
t.integer "user_id"
t.integer "magazine_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

add_index "joinmagazines", ["magazine_id"], name: "index_joinmagazines_on_magazine_id"
add_index "joinmagazines", ["user_id"], name: "index_joinmagazines_on_user_id"

create_table "magazines", force: :cascade do |t|
t.string "name"
t.text "decription"
Expand Down
Loading

0 comments on commit 732edf5

Please sign in to comment.