Permalink
Browse files

connected users and uploads

  • Loading branch information...
1 parent 90efb87 commit 0802d58b860634649c68a90a7ec563bcc654c61c @strix3000 strix3000 committed Feb 24, 2012
@@ -1,11 +1,12 @@
class UploadsController < ApplicationController
-skip_before_filter :require_login
+skip_before_filter :require_login, :only => [:index, :show]
#Page where all Uploads are available
def index
@files = Upload.all
- @title = "Downloads"
+@user = User.find(1)
+ @title = "Downloads"
respond_to do |format|
format.html # index.html.erb
format.json { render json: @files }
@@ -39,7 +40,7 @@ def edit
# POST /files.json
def create
@file = Upload.new(params[:upload])
-
+ @file.user = current_user
respond_to do |format|
if @file.save
format.html { redirect_to(:uploads, :notice => 'file was successfully created.') }
@@ -79,4 +80,13 @@ def destroy
end
end
+ def user_uploads
+ @files = current_user.uploads.all
+ end
+
+
+
+
+
+
end
View
@@ -1,4 +1,11 @@
class Upload < ActiveRecord::Base
attr_accessible :name, :description, :file
mount_uploader :file, FileUploader
+
+#Relations
+ belongs_to :user
+# has_many :users
+# has_many :users , :through => :users_uploads
+
+#Validation
end
View
@@ -2,6 +2,15 @@ class User < ActiveRecord::Base
attr_accessible :email, :password, :password_confirmation, :image, :username
authenticates_with_sorcery!
+#Relations
+ has_many :uploads
+# has_many :uploads, :through => :users_uploads
+
+
+
+
+
+#Validation
email_regex = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
validates_length_of :password, :within => 3..25,
@@ -0,0 +1,8 @@
+class UsersUploads < ActiveRecord::Base
+#Relations
+# belongs_to :user
+# belongs_to :upload
+#Validations
+
+
+end
@@ -25,8 +25,10 @@
<% if current_user %>
<li><%= link_to "Edit Profile", edit_user_path(current_user.id) %></li>
<li><%= link_to "Logout", :logout %></li>
- <li><%= link_to "my_downloads", :downloads %></li>
- <% else %>
+ <li><%= link_to "downloads", :downloads %></li>
+ <li><%= link_to "my_downloads", :my_downloads %></li>
+
+ <% else %>
<li><%= link_to "Register", new_user_path %></li>
<li><%= link_to "Login", :login %></li>
<% end %>
@@ -4,7 +4,7 @@
<tr>
<th>Filename</th>
<th>Description</th>
- <th></th>
+ <th>Belongs to</th>
<th></th>
<th></th>
</tr>
@@ -13,7 +13,9 @@
<tr>
<td><%= file.name %></td>
<td><%= file.description %></td>
- <td><%= link_to 'Show', file %></td>
+ <td><%= link_to "#{file.user.username}", user_path(file.user) %></td>
+
+ <td><%= link_to 'Show', file %></td>
<td><%= link_to 'Edit', edit_upload_path(file) %></td>
<!-- <td><%= link_to 'Destroy', file, confirm: 'Are you sure?', method: :delete %></td> -->
<td><%= link_to 'Destroy', file, method: :delete %></td>
@@ -0,0 +1,25 @@
+<h1>Listing Uploads</h1>
+
+<table>
+ <tr>
+ <th>Filename</th>
+ <th>Description</th>
+ <th></th>
+ <th></th>
+ <th></th>
+ </tr>
+
+<% @files.each do |file| %>
+ <tr>
+ <td><%= file.name %></td>
+ <td><%= file.description %></td>
+ <td><%= link_to 'Show', file %></td>
+ <td><%= link_to 'Edit', edit_upload_path(file) %></td>
+ <!-- <td><%= link_to 'Destroy', file, confirm: 'Are you sure?', method: :delete %></td> -->
+ <td><%= link_to 'Destroy', file, method: :delete %></td>
+</tr>
+<% end %>
+</table>
+
+<br />
+ <td><%= link_to 'New', new_upload_path %></td>
View
@@ -8,7 +8,7 @@
match 'login' => 'user_sessions#new', :as => :login
match 'logout' => 'user_sessions#destroy', :as => :logout
match 'downloads' => 'uploads#index',:as => :downloads
-
+ match 'my_downloads' => 'uploads#user_uploads', :as => :my_downloads
# The priority is based upon order of creation:
# first created -> highest priority.
@@ -0,0 +1,10 @@
+class CreateUsersUploads < ActiveRecord::Migration
+ def change
+ create_table :users_uploads do |t|
+ t.integer :user_id
+ t.integer :upload_ip
+
+ t.timestamps
+ end
+ end
+end
@@ -0,0 +1,9 @@
+class Add < ActiveRecord::Migration
+ def change
+ add_column :uploads, :user_id, :integer
+
+ end
+
+ def down
+ end
+end
View
@@ -11,14 +11,15 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20120213192439) do
+ActiveRecord::Schema.define(:version => 20120224131235) do
create_table "uploads", :force => true do |t|
t.string "name"
t.text "description"
t.string "file"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
+ t.integer "user_id"
end
create_table "users", :force => true do |t|
@@ -31,4 +32,11 @@
t.string "image"
end
+ create_table "users_uploads", :force => true do |t|
+ t.integer "user_id"
+ t.integer "upload_ip"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ end
+
end

0 comments on commit 0802d58

Please sign in to comment.