Permalink
Browse files

Merge branches 'file_uploader' and 'master'

  • Loading branch information...
2 parents db20261 + 47f9bbe commit 29652bbd7b6e804920d85c7f9806557b62b20bd7 @strix3000 strix3000 committed Feb 21, 2012
Showing with 434 additions and 2 deletions.
  1. +3 −0 app/assets/javascripts/upload.js.coffee
  2. +3 −0 app/assets/stylesheets/upload.css.scss
  3. +16 −0 app/controllers/upload_controller.rb~
  4. +82 −0 app/controllers/uploads_controller.rb
  5. +82 −0 app/controllers/uploads_controller.rb~
  6. +2 −0 app/helpers/upload_helper.rb
  7. +4 −0 app/models/upload.rb
  8. +3 −0 app/models/upload.rb~
  9. +3 −0 app/models/uploads.rb
  10. +5 −0 app/models/uploads.rb~
  11. +48 −0 app/uploaders/file_uploader.rb
  12. +2 −0 app/views/layouts/application.html.erb
  13. +4 −2 app/views/layouts/application.html.erb~
  14. +30 −0 app/views/uploads/_form.html.erb
  15. +38 −0 app/views/uploads/_form.html.erb~
  16. +6 −0 app/views/uploads/edit.html.erb
  17. +6 −0 app/views/uploads/edit.html.erb~
  18. 0 app/views/uploads/edit~
  19. +25 −0 app/views/uploads/index.html.erb
  20. +24 −0 app/views/uploads/index.html.erb~
  21. 0 app/views/uploads/index~
  22. +5 −0 app/views/uploads/new.html.erb
  23. +5 −0 app/views/uploads/new.html.erb~
  24. +19 −0 app/views/uploads/show.html.erb
  25. +19 −0 app/views/uploads/show.html.erb~
  26. 0 app/views/uploads/show~
  27. BIN public/uploads/tmp/20120130-1703-18556-4668/pirate-bay-wallpaper.jpg
  28. BIN public/uploads/tmp/20120130-1703-18556-4668/thumb_pirate-bay-wallpaper.jpg
  29. BIN public/uploads/tmp/20120130-1703-18556-6079/pirate-bay-wallpaper.jpg
  30. BIN public/uploads/tmp/20120130-1703-18556-6079/thumb_pirate-bay-wallpaper.jpg
  31. BIN public/uploads/tmp/20120130-1714-18556-2872/avatar_b07.jpg
  32. BIN public/uploads/tmp/20120130-1714-18556-2872/thumb_avatar_b07.jpg
  33. BIN public/uploads/tmp/20120130-1714-18556-4551/avatar_b07.jpg
  34. BIN public/uploads/tmp/20120130-1714-18556-4551/thumb_avatar_b07.jpg
  35. BIN public/uploads/tmp/20120130-1714-18556-5609/avatar_b07.jpg
  36. BIN public/uploads/tmp/20120130-1714-18556-5609/thumb_avatar_b07.jpg
  37. BIN public/uploads/tmp/20120130-1715-18556-2435/avatar_b07.jpg
  38. BIN public/uploads/tmp/20120130-1715-18556-2435/thumb_avatar_b07.jpg
  39. BIN public/uploads/tmp/20120130-1716-18556-8468/avatar_b07.jpg
  40. BIN public/uploads/tmp/20120130-1716-18556-8468/thumb_avatar_b07.jpg
  41. BIN public/uploads/tmp/20120130-1716-18556-8849/avatar_b07.jpg
  42. BIN public/uploads/tmp/20120130-1716-18556-8849/thumb_avatar_b07.jpg
  43. BIN public/uploads/user/image/1/pirate-bay-wallpaper.jpg
  44. BIN public/uploads/user/image/1/thumb_pirate-bay-wallpaper.jpg
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
@@ -0,0 +1,3 @@
+// Place all the styles related to the upload controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
@@ -0,0 +1,16 @@
+class UploadController < ApplicationController
+
+skip_before_filter :require_login
+
+#Page where all uploads are available
+def index
+end
+
+#Shows only one chosen file? with description.
+def show
+end
+
+def edit
+end
+
+end
@@ -0,0 +1,82 @@
+class UploadsController < ApplicationController
+
+skip_before_filter :require_login
+
+#Page where all Uploads are available
+def index
+@files = Upload.all
+
+ respond_to do |format|
+ format.html # index.html.erb
+ format.json { render json: @files }
+ end
+end
+
+#Shows only one chosen file? with description.
+def show
+ @file = Upload.find(params[:id])
+ respond_to do |format|
+ format.html # show.html.erb
+ format.json { render json: @file }
+ end
+end
+
+def new
+ @file = Upload.new
+
+ respond_to do |format|
+ format.html # new.html.erb
+ format.json { render json: @file }
+ end
+ end
+
+ # GET /files/1/edit
+ def edit
+ @file = Upload.find(params[:id])
+ end
+
+ # POST /files
+ # POST /files.json
+ def create
+ @file = Upload.new(params[:upload])
+
+ respond_to do |format|
+ if @file.save
+ format.html { redirect_to(:uploads, :notice => 'file was successfully created.') }
+ format.json { render json: @file, status: :created, location: @file }
+ else
+ format.html { render action: "new" }
+ format.json { render json: @file.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # PUT /files/1
+ # PUT /files/1.json
+ def update
+ @file = Upload.find(params[:id])
+
+ respond_to do |format|
+ if @file.update_attributes(params[:file])
+ format.html { redirect_to @file, notice: 'file was successfully updated.' }
+ format.json { head :ok }
+ else
+ format.html { render action: "edit" }
+ format.json { render json: @file.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # DELETE /files/1
+ # DELETE /files/1.json
+ def destroy
+ @file = Upload.find(params[:id])
+ @file.destroy
+
+ respond_to do |format|
+ format.html { redirect_to uploads_url }
+ format.json { head :ok }
+ end
+ end
+
+end
@@ -0,0 +1,82 @@
+class UploadsController < ApplicationController
+
+skip_before_filter :require_login
+
+#Page where all Uploads are available
+def index
+@files = Upload.all
+
+ respond_to do |format|
+ format.html # index.html.erb
+ format.json { render json: @files }
+ end
+end
+
+#Shows only one chosen file? with description.
+def show
+ @file = Upload.find(params[:id])
+ respond_to do |format|
+ format.html # show.html.erb
+ format.json { render json: @file }
+ end
+end
+
+def new
+ @file = Upload.new
+
+ respond_to do |format|
+ format.html # new.html.erb
+ format.json { render json: @file }
+ end
+ end
+
+ # GET /files/1/edit
+ def edit
+ @file = Upload.find(params[:id])
+ end
+
+ # POST /files
+ # POST /files.json
+ def create
+ @file = Upload.new(params[:upload])
+
+ respond_to do |format|
+ if @file.save
+ format.html { redirect_to(:uploads, :notice => 'file was successfully created.') }
+ format.json { render json: @file, status: :created, location: @file }
+ else
+ format.html { render action: "new" }
+ format.json { render json: @file.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # PUT /files/1
+ # PUT /files/1.json
+ def update
+ @file = Upload.find(params[:id])
+
+ respond_to do |format|
+ if @file.update_attributes(params[:file])
+ format.html { redirect_to @file, notice: 'file was successfully updated.' }
+ format.json { head :ok }
+ else
+ format.html { render action: "edit" }
+ format.json { render json: @file.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # DELETE /files/1
+ # DELETE /files/1.json
+ def destroy
+ @file = Upload.find(params[:id])
+ @file.destroy
+
+ respond_to do |format|
+ format.html { redirect_to uploads_url }
+ format.json { head :ok }
+ end
+ end
+
+end
@@ -0,0 +1,2 @@
+module UploadHelper
+end
View
@@ -0,0 +1,4 @@
+class Upload < ActiveRecord::Base
+ attr_accessible :name, :description, :file
+ mount_uploader :file, FileUploader
+end
View
@@ -0,0 +1,3 @@
+class Upload < ActiveRecord::Base
+ attr_accessible :name, :description
+end
View
@@ -0,0 +1,3 @@
+class Uploads < ActiveRecord::Base
+ mount_uploader :file, FileUploader
+end
View
@@ -0,0 +1,5 @@
+class Uploads < ActiveRecord::Base
+ mount_uploader :file, FileUploader
+ attr_accessible :name, :description, :file
+
+end
@@ -0,0 +1,48 @@
+# encoding: utf-8
+
+class FileUploader < CarrierWave::Uploader::Base
+
+ # Include RMagick or MiniMagick support:
+ # include CarrierWave::RMagick
+ # include CarrierWave::MiniMagick
+
+ # Choose what kind of storage to use for this uploader:
+ storage :file
+ # storage :fog
+
+ # Override the directory where uploaded files will be stored.
+ # This is a sensible default for uploaders that are meant to be mounted:
+ def store_dir
+ "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
+ end
+
+ # Provide a default URL as a default if there hasn't been a file uploaded:
+ # def default_url
+ # "/images/fallback/" + [version_name, "default.png"].compact.join('_')
+ # end
+
+ # Process files as they are uploaded:
+ # process :scale => [200, 300]
+ #
+ # def scale(width, height)
+ # # do something
+ # end
+
+ # Create different versions of your uploaded files:
+ # version :thumb do
+ # process :scale => [50, 50]
+ # end
+
+ # Add a white list of extensions which are allowed to be uploaded.
+ # For images you might use something like this:
+ # def extension_white_list
+ # %w(jpg jpeg gif png)
+ # end
+
+ # Override the filename of the uploaded files:
+ # Avoid using model.id or version_name here, see uploader/store.rb for details.
+ # def filename
+ # "something.jpg" if original_filename
+ # end
+
+end
@@ -12,6 +12,8 @@
<% if current_user %>
<%= link_to "Edit Profile", edit_user_path(current_user.id) %>
<%= link_to "Logout", :logout %>
+ <%= link_to "my_downloads", :downloads %>
+
<% else %>
<%= link_to "Register", new_user_path %> |
<%= link_to "Login", :login %>
@@ -7,11 +7,13 @@
<%= csrf_meta_tags %>
</head>
<body>
-
+
<div id="nav">
<% if current_user %>
<%= link_to "Edit Profile", edit_user_path(current_user.id) %>
<%= link_to "Logout", :logout %>
+ <%= link_to "my_downloads" %>
+
<% else %>
<%= link_to "Register", new_user_path %> |
<%= link_to "Login", :login %>
@@ -22,6 +24,6 @@
<p id="alert"><%= alert %></p>
</div>
<%= yield %>
-
+
</body>
</html>
@@ -0,0 +1,30 @@
+<%= form_for(@file) do |f| %>
+ <% if @file.errors.any? %>
+ <div id="error_explanation">
+ <h2><%= pluralize(@file.errors.count, "error") %> prohibited this file from being saved:</h2>
+
+ <ul>
+ <% @file.errors.full_messages.each do |msg| %>
+ <li><%= msg %></li>
+ <% end %>
+ </ul>
+ </div>
+ <% end %>
+
+ <div class="field">
+ <%= f.file_field :file %><br />
+ </div>
+
+ <div class="field">
+ <%= f.label :name %><br />
+ <%= f.text_field :name %>
+ </div>
+ <div class="field">
+ <%= f.label :description %><br />
+ <%= f.text_field :description %>
+ </div>
+ </div>
+ <div class="actions">
+ <%= f.submit %>
+ </div>
+<% end %>
@@ -0,0 +1,38 @@
+<%= form_for(@user) do |f| %>
+ <% if @user.errors.any? %>
+ <div id="error_explanation">
+ <h2><%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:</h2>
+
+ <ul>
+ <% @user.errors.full_messages.each do |msg| %>
+ <li><%= msg %></li>
+ <% end %>
+ </ul>
+ </div>
+ <% end %>
+
+ <div class="field">
+ <%= f.file_field :image %><br />
+ </div>
+
+ <div class="field">
+ <%= f.label :username %><br />
+ <%= f.text_field :username %>
+ </div>
+ <div class="field">
+ <%= f.label :email %><br />
+ <%= f.text_field :email %>
+ </div>
+ <div class="field">
+ <%= f.label :password %><br />
+ <%= f.password_field :password %>
+ </div>
+ <div class="field">
+ <%= f.label :password_confirmation %><br />
+ <%= f.password_field :password_confirmation %>
+ </div>
+ </div>
+ <div class="actions">
+ <%= f.submit %>
+ </div>
+<% end %>
@@ -0,0 +1,6 @@
+<h1>Editing user</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Show', @file %> |
+<%= link_to 'Back', uploads_path %>
@@ -0,0 +1,6 @@
+<h1>Editing user</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Show', @file %> |
+<%= link_to 'Back', files_path %>
View
No changes.
Oops, something went wrong.

0 comments on commit 29652bb

Please sign in to comment.