Skip to content
Browse files

adding dwonloads to favourite - working.

  • Loading branch information...
1 parent 46bf324 commit 981a8aa4e74a8d1f5893e2157d0b3d10c861a136 @strix3000 strix3000 committed
Showing with 7 additions and 9 deletions.
  1. +4 −6 app/controllers/uploads_controller.rb
  2. +2 −2 app/models/users_upload.rb
  3. +1 −1 app/views/uploads/index.html.erb
View
10 app/controllers/uploads_controller.rb
@@ -94,14 +94,12 @@ def add_to_favorite
end
end
- def delete_from_favorites
- id = params[:id]
- @favourite_upload = UsersUpload.find_by_saved_upload(params[:id])
- if @favourite_upload.destroy
+ def delete_from_favorites
+ @favourite_upload = UsersUpload.where(:upload_id => params[:id],:user_id => current_user.id)
+ @favourite_upload.first.destroy
respond_to do |format|
format.html { redirect_to my_downloads_url }
- end
- end
+ end
end
View
4 app/models/users_upload.rb
@@ -3,6 +3,6 @@ class UsersUpload < ActiveRecord::Base
belongs_to :user
belongs_to :upload
#Validations
-
-
+validates :user_id, :presence => true
+validates :upload_id, :presence => true
end
View
2 app/views/uploads/index.html.erb
@@ -19,7 +19,7 @@
<td><%= link_to 'Edit', edit_upload_path(file) %></td>
<% if current_user.uploads.include?(file) %>
<td><%= link_to 'Destroy', file , method: :delete %></td>
- <% else if current_user.users_upload.include?(file)%>
+ <% else if current_user.saved_uploads.include?(file)%>
<td>Already_in_favorites</td>
<% else %>
<td><%= link_to 'add_to_favorite', add_upload_to_favorite_path(file) %></td>

0 comments on commit 981a8aa

Please sign in to comment.
Something went wrong with that request. Please try again.