Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fixed bugs in downloads

  • Loading branch information...
commit 398202c08979670dcec8e9e5271beba2c28f5b8a 1 parent 2e1b83e
strix3000 strix3000 authored
2  app/controllers/messages_controller.rb
View
@@ -2,7 +2,7 @@ class MessagesController < ApplicationController
def create
@recipient = User.find(params[:id])
- @message = Message.new(:content => params[:content], :user => current_user)
+ @message = Message.new(:content => params[:content], :user => current_user,)
@message.save
mes_recipient = MessageRecipient.new(:message => @message, :user => @recipient)
mes_recipient.save
24 app/controllers/uploads_controller.rb
View
@@ -2,14 +2,14 @@ class UploadsController < ApplicationController
skip_before_filter :require_login, :only => [:index, :show]
-#Page where all Uploads are available
def index
-@files = Upload.all
- @title = "Downloads"
- respond_to do |format|
- format.html # index.html.erb
- format.json { render json: @files }
- end
+
+ if User.exists?(params[:id])
+ user = User.find(params[:id])
+ @files = user.uploads + user.saved_uploads
+ else
+ redirect_to(:my_downloads, :notice => "Files not found")
+ end
end
#Shows only one chosen file? with description.
@@ -65,12 +65,12 @@ def destroy
@file.destroy
end
- def user_uploads
- @files = current_user.saved_uploads + current_user.uploads
- end
+def favourite
+ @files = current_user.saved_uploads + current_user.uploads
+end
- def add_to_favorite
- favourite_upload = UsersUpload.new(:user => current_user,:upload => Upload.find(params[:id]))
+def add_to_favorite
+ favourite_upload = UsersUpload.new(:user => current_user,:upload => Upload.find(params[:id]))
if favourite_upload.save
respond_to do |format|
format.html { redirect_to uploads_url }
8 app/controllers/user_sessions_controller.rb
View
@@ -10,13 +10,11 @@ def index
def create
respond_to do |format|
- if @user = login(params[:username],params[:password])
+ if @user = login(params[:username],params[:password])
format.html { redirect_back_or_to(root_path, :notice => 'Login successful.') }
- format.xml { render :xml => @user, :status => :created, :location => @user }
- else
+ else
format.html { flash.now[:alert] = "Login failed."; render :action => "new" }
- format.xml { render :xml => @user.errors, :status => :unprocessable_entity }
- end
+ end
end
end
2  app/controllers/users_controller.rb
View
@@ -48,7 +48,7 @@ def edit
# POST /users.json
def create
@user = User.new(params[:user])
- @title = "Edit user profile1"
+ @title = "Edit user profile"
respond_to do |format|
if @user.save
UserMailer.welcome_email(@user).deliver
8 app/controllers/users_controller.rb~
View
@@ -90,12 +90,4 @@ class UsersController < ApplicationController
end
end
-def mercury_update
- @user = User.find(params[:id])
- page = @user.posts.find_by_id(params[:id])
- page.content = params[:content][:page_content][:value]
- post.save!
- render text: "Post was updated"
-end
-
end
3  app/models/message.rb
View
@@ -6,4 +6,7 @@ class Message < ActiveRecord::Base
#Validations
validate :user_id, :presence => true
+#methods
+
+
end
13 app/views/layouts/_header.html.erb
View
@@ -2,16 +2,17 @@
<%= image_tag("logo.png", :alt => "Ruby School", :class => "round") %>
<nav class="round">
<ul>
- <li><%= link_to "Home", root_path %></li>
- <li><%= link_to "Users", :userslist %></li>
+ <li><%= link_to "Главная", root_path %></li>
+ <li><%= link_to "Пользователи", :userslist %></li>
<% if current_user %>
- <li><%= link_to "Редактировать", edit_user_path(current_user.id) %></li>
+ <li><%= link_to "Профиль", edit_user_path(current_user) %></li>
<li><%= link_to "Выход", :logout %></li>
- <li><%= link_to "Мои загрузки", :downloads %></li>
- <% else %>
+ <li><%= link_to "Загрузки", :my_downloads %></li>
+ <li><%= link_to "Сообщения", :my_messages %></li>
+ <% else %>
<li><%= link_to "Регистрация", new_user_path %></li>
<li><%= link_to "Вход", :login %></li>
<% end %>
</ul>
- </nav>
+ </nav>
</header>
26 app/views/layouts/application.html.erb
View
@@ -1,30 +1,12 @@
<!DOCTYPE html>
<html>
- <%= render 'layouts/style_and_meta' %>
+<%= render 'layouts/style_and_meta' %>
- <body>
+<body>
<div class="container">
-
- <header>
- <%= image_tag("logo.png", :alt => "Ruby School", :class => "round") %>
- <nav class="round">
- <ul>
- <li><%= link_to "Главная", root_path %></li>
- <li><%= link_to "Пользователи", :userslist %></li>
- <% if current_user %>
- <li><%= link_to "Профиль", edit_user_path(current_user.id) %></li>
- <li><%= link_to "Выход", :logout %></li>
- <li><%= link_to "Загрузки", :downloads %></li>
- <li><%= link_to "Избранное", :my_downloads %></li>
-
- <% else %>
- <li><%= link_to "Регистрация", new_user_path %></li>
- <li><%= link_to "Вход", :login %></li>
- <% end %>
- </ul>
- </nav>
- </header>
+<%= render 'layouts/header' %>
+
<div>
<p id="notice"><%= notice %></p>
34 app/views/uploads/favourite.html.erb
View
@@ -0,0 +1,34 @@
+<h1>Загрузки</h1>
+<table>
+ <tr>
+ <th>Filename</th>
+ <th>Description</th>
+ <th></th>
+ <th></th>
+ <th></th>
+ </tr>
+<% if @files %>
+<% @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>
+ <% if file.user?(current_user) %>
+ <td><%= link_to 'Destroy file', file, method: :delete %></td>
+ <% else %>
+ <td><%= link_to 'Remove from favorite', delete_upload_from_favorite_path(file) %></td>
+ <% end %>
+ <td><%= link_to "Download", file.file_url %></td>
+</tr>
+<% end %>
+<% else %>
+ <tr>
+ <td>No files found for <%= current_user.username %></td>
+ <tr>
+<% end %>
+
+</table>
+
+<br />
+ <td><%= link_to 'New', new_upload_path %></td>
2  app/views/users/show.html.erb
View
@@ -5,7 +5,7 @@
<strong>E-mail</strong> <%= @user.email %><br />
<strong>URL</strong> <%= link_to user_path(@user), @user %><br />
<strong>Posts</strong> <%= link_to @user.posts.count, userposts_path %>
- <%= link_to "Downloads", :downloads %>
+ <p><%= link_to "Downloads", :downloads %></p>
<br>
<%= link_to 'Edit', edit_user_path(@user) %> | <%= link_to 'Back', users_path %>
</td>
7 config/routes.rb
View
@@ -11,12 +11,15 @@
match 'login' => 'user_sessions#new', :as => :login
match 'userslist' => 'users#index', :as => :userslist
match 'logout' => 'user_sessions#destroy', :as => :logout
- match 'downloads' => 'uploads#index',:as => :downloads
- match 'my_downloads' => 'uploads#user_uploads', :as => :my_downloads
+
+ match 'downloads/:id' => 'uploads#index', :as => :downloads
+ match 'my_downloads' => 'uploads#favourite', :as => :my_downloads
match 'add_upload_to_favorite/:id' => 'uploads#add_to_favorite', :as => :add_upload_to_favorite
match 'delete_upload_from_favorite/:id' => 'uploads#delete_from_favorites', :as => :delete_upload_from_favorite
+
match 'users/:id/posts' => 'posts#userposts', :as => :userposts
match 'users/:id/posts/:id' => 'posts#userpost', :as => :userpost
+
match 'send_message/:id' => 'messages#create', :as => :send_message
match 'my_messages' => "messages#user_messages", :as => :my_messages
# The priority is based upon order of creation:
Please sign in to comment.
Something went wrong with that request. Please try again.