diff options
Diffstat (limited to 'app')
| -rw-r--r-- | app/controllers/assets_controller.rb | 88 | ||||
| -rw-r--r-- | app/helpers/assets_helper.rb | 2 | ||||
| -rw-r--r-- | app/models/asset.rb | 10 | ||||
| -rw-r--r-- | app/views/admin/_menu.html.erb | 1 | ||||
| -rw-r--r-- | app/views/assets/edit.html.erb | 12 | ||||
| -rw-r--r-- | app/views/assets/index.html.erb | 20 | ||||
| -rw-r--r-- | app/views/assets/new.html.erb | 17 | ||||
| -rw-r--r-- | app/views/assets/show.html.erb | 10 | ||||
| -rw-r--r-- | app/views/layouts/assets.html.erb | 17 |
9 files changed, 177 insertions, 0 deletions
diff --git a/app/controllers/assets_controller.rb b/app/controllers/assets_controller.rb new file mode 100644 index 0000000..4734a54 --- /dev/null +++ b/app/controllers/assets_controller.rb | |||
| @@ -0,0 +1,88 @@ | |||
| 1 | class AssetsController < ApplicationController | ||
| 2 | |||
| 3 | layout 'admin' | ||
| 4 | |||
| 5 | # GET /assets | ||
| 6 | # GET /assets.xml | ||
| 7 | def index | ||
| 8 | @assets = Asset.all | ||
| 9 | |||
| 10 | respond_to do |format| | ||
| 11 | format.html # index.html.erb | ||
| 12 | format.xml { render :xml => @assets } | ||
| 13 | end | ||
| 14 | end | ||
| 15 | |||
| 16 | # GET /assets/1 | ||
| 17 | # GET /assets/1.xml | ||
| 18 | def show | ||
| 19 | @asset = Asset.find(params[:id]) | ||
| 20 | |||
| 21 | respond_to do |format| | ||
| 22 | format.html # show.html.erb | ||
| 23 | format.xml { render :xml => @asset } | ||
| 24 | end | ||
| 25 | end | ||
| 26 | |||
| 27 | # GET /assets/new | ||
| 28 | # GET /assets/new.xml | ||
| 29 | def new | ||
| 30 | @asset = Asset.new | ||
| 31 | |||
| 32 | respond_to do |format| | ||
| 33 | format.html # new.html.erb | ||
| 34 | format.xml { render :xml => @asset } | ||
| 35 | end | ||
| 36 | end | ||
| 37 | |||
| 38 | # GET /assets/1/edit | ||
| 39 | def edit | ||
| 40 | @asset = Asset.find(params[:id]) | ||
| 41 | end | ||
| 42 | |||
| 43 | # POST /assets | ||
| 44 | # POST /assets.xml | ||
| 45 | def create | ||
| 46 | @asset = Asset.new(params[:asset]) | ||
| 47 | |||
| 48 | respond_to do |format| | ||
| 49 | if @asset.save | ||
| 50 | flash[:notice] = 'Asset was successfully created.' | ||
| 51 | format.html { redirect_to(@asset) } | ||
| 52 | format.xml { render :xml => @asset, :status => :created, :location => @asset } | ||
| 53 | else | ||
| 54 | format.html { render :action => "new" } | ||
| 55 | format.xml { render :xml => @asset.errors, :status => :unprocessable_entity } | ||
| 56 | end | ||
| 57 | end | ||
| 58 | end | ||
| 59 | |||
| 60 | # PUT /assets/1 | ||
| 61 | # PUT /assets/1.xml | ||
| 62 | def update | ||
| 63 | @asset = Asset.find(params[:id]) | ||
| 64 | |||
| 65 | respond_to do |format| | ||
| 66 | if @asset.update_attributes(params[:asset]) | ||
| 67 | flash[:notice] = 'Asset was successfully updated.' | ||
| 68 | format.html { redirect_to(@asset) } | ||
| 69 | format.xml { head :ok } | ||
| 70 | else | ||
| 71 | format.html { render :action => "edit" } | ||
| 72 | format.xml { render :xml => @asset.errors, :status => :unprocessable_entity } | ||
| 73 | end | ||
| 74 | end | ||
| 75 | end | ||
| 76 | |||
| 77 | # DELETE /assets/1 | ||
| 78 | # DELETE /assets/1.xml | ||
| 79 | def destroy | ||
| 80 | @asset = Asset.find(params[:id]) | ||
| 81 | @asset.destroy | ||
| 82 | |||
| 83 | respond_to do |format| | ||
| 84 | format.html { redirect_to(assets_url) } | ||
| 85 | format.xml { head :ok } | ||
| 86 | end | ||
| 87 | end | ||
| 88 | end | ||
diff --git a/app/helpers/assets_helper.rb b/app/helpers/assets_helper.rb new file mode 100644 index 0000000..9824bb4 --- /dev/null +++ b/app/helpers/assets_helper.rb | |||
| @@ -0,0 +1,2 @@ | |||
| 1 | module AssetsHelper | ||
| 2 | end | ||
diff --git a/app/models/asset.rb b/app/models/asset.rb new file mode 100644 index 0000000..c9c6296 --- /dev/null +++ b/app/models/asset.rb | |||
| @@ -0,0 +1,10 @@ | |||
| 1 | class Asset < ActiveRecord::Base | ||
| 2 | has_attached_file( | ||
| 3 | :upload, | ||
| 4 | :styles => { | ||
| 5 | :normal => "450x450", | ||
| 6 | :medium => "300x300", | ||
| 7 | :thumb => "100x100", | ||
| 8 | } | ||
| 9 | ) | ||
| 10 | end | ||
diff --git a/app/views/admin/_menu.html.erb b/app/views/admin/_menu.html.erb index 8f48822..5ae4307 100644 --- a/app/views/admin/_menu.html.erb +++ b/app/views/admin/_menu.html.erb | |||
| @@ -2,4 +2,5 @@ | |||
| 2 | 2 | ||
| 3 | <%= link_to 'Overview', :controller => :admin, :action => 'index' %> | 3 | <%= link_to 'Overview', :controller => :admin, :action => 'index' %> |
| 4 | <%= link_to 'Nodes', nodes_path, selected?('nodes') %> | 4 | <%= link_to 'Nodes', nodes_path, selected?('nodes') %> |
| 5 | <%= link_to 'Assets', assets_path, selected?('assets') %> | ||
| 5 | <%= link_to 'User', users_path, selected?('users') %> > \ No newline at end of file | 6 | <%= link_to 'User', users_path, selected?('users') %> > \ No newline at end of file |
diff --git a/app/views/assets/edit.html.erb b/app/views/assets/edit.html.erb new file mode 100644 index 0000000..d60db94 --- /dev/null +++ b/app/views/assets/edit.html.erb | |||
| @@ -0,0 +1,12 @@ | |||
| 1 | <h1>Editing asset</h1> | ||
| 2 | |||
| 3 | <% form_for(@asset) do |f| %> | ||
| 4 | <%= f.error_messages %> | ||
| 5 | |||
| 6 | <p> | ||
| 7 | <%= f.submit 'Update' %> | ||
| 8 | </p> | ||
| 9 | <% end %> | ||
| 10 | |||
| 11 | <%= link_to 'Show', @asset %> | | ||
| 12 | <%= link_to 'Back', assets_path %> \ No newline at end of file | ||
diff --git a/app/views/assets/index.html.erb b/app/views/assets/index.html.erb new file mode 100644 index 0000000..c9be684 --- /dev/null +++ b/app/views/assets/index.html.erb | |||
| @@ -0,0 +1,20 @@ | |||
| 1 | <% content_for :subnavigation do %> | ||
| 2 | <%= link_to 'New asset', new_asset_path %> | ||
| 3 | <% end %> | ||
| 4 | |||
| 5 | |||
| 6 | <table> | ||
| 7 | <tr> | ||
| 8 | </tr> | ||
| 9 | |||
| 10 | <% @assets.each do |asset| %> | ||
| 11 | <tr> | ||
| 12 | <td><%= image_tag asset.upload.url(:thumb) %></td> | ||
| 13 | <td><%= link_to asset.name, asset.upload.url %></td> | ||
| 14 | <td><%= asset.upload.content_type %></td> | ||
| 15 | <td><%= link_to 'Show', asset %></td> | ||
| 16 | <td><%= link_to 'Edit', edit_asset_path(asset) %></td> | ||
| 17 | <td><%= link_to 'Destroy', asset, :confirm => 'Are you sure?', :method => :delete %></td> | ||
| 18 | </tr> | ||
| 19 | <% end %> | ||
| 20 | </table> \ No newline at end of file | ||
diff --git a/app/views/assets/new.html.erb b/app/views/assets/new.html.erb new file mode 100644 index 0000000..366488f --- /dev/null +++ b/app/views/assets/new.html.erb | |||
| @@ -0,0 +1,17 @@ | |||
| 1 | <h1>New asset</h1> | ||
| 2 | |||
| 3 | <% form_for(@asset, :html => { :multipart => true }) do |f| %> | ||
| 4 | <%= f.error_messages %> | ||
| 5 | |||
| 6 | <p> | ||
| 7 | <%= f.label :name %><br /> | ||
| 8 | <%= f.text_field :name %> | ||
| 9 | </p> | ||
| 10 | |||
| 11 | <p> | ||
| 12 | <%= f.file_field :upload %> | ||
| 13 | <%= f.submit 'Create' %> | ||
| 14 | </p> | ||
| 15 | <% end %> | ||
| 16 | |||
| 17 | <%= link_to 'Back', assets_path %> \ No newline at end of file | ||
diff --git a/app/views/assets/show.html.erb b/app/views/assets/show.html.erb new file mode 100644 index 0000000..dd657d3 --- /dev/null +++ b/app/views/assets/show.html.erb | |||
| @@ -0,0 +1,10 @@ | |||
| 1 | <% content_for :subnavigation do %> | ||
| 2 | <%= link_to 'Edit', edit_asset_path(@asset) %> | ||
| 3 | <%= link_to 'Back', assets_path %> | ||
| 4 | <% end %> | ||
| 5 | |||
| 6 | |||
| 7 | |||
| 8 | <%= image_tag @asset.upload.url(:medium) %><br /> | ||
| 9 | <%= @asset.upload.content_type %><br /> | ||
| 10 | <%= "#{@asset.upload.size/1024} KB" %><br /> \ No newline at end of file | ||
diff --git a/app/views/layouts/assets.html.erb b/app/views/layouts/assets.html.erb new file mode 100644 index 0000000..9d629c8 --- /dev/null +++ b/app/views/layouts/assets.html.erb | |||
| @@ -0,0 +1,17 @@ | |||
| 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" | ||
| 2 | "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | ||
| 3 | |||
| 4 | <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> | ||
| 5 | <head> | ||
| 6 | <meta http-equiv="content-type" content="text/html;charset=UTF-8" /> | ||
| 7 | <title>Assets: <%= controller.action_name %></title> | ||
| 8 | <%= stylesheet_link_tag 'scaffold' %> | ||
| 9 | </head> | ||
| 10 | <body> | ||
| 11 | |||
| 12 | <p style="color: green"><%= flash[:notice] %></p> | ||
| 13 | |||
| 14 | <%= yield %> | ||
| 15 | |||
| 16 | </body> | ||
| 17 | </html> | ||
