forked from publiclab/plots2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
160 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
class ImagesController < ApplicationController | ||
|
||
def create | ||
if current_user && current_user.username == "warren" | ||
@image = Image.new({ | ||
:uid => current_user.uid, | ||
:photo => params[:image][:photo], | ||
:title => params[:image][:title], | ||
:notes => params[:image][:notes] | ||
}) | ||
@image.nid = DrupalNode.find params[:nid] if params[:nid] | ||
if @image.save! | ||
flash[:notice] = "Image saved." | ||
else | ||
flash[:error] = "The image could not be saved." | ||
end | ||
redirect_to "/profile/"+current_user.username | ||
else | ||
prompt_login "You must be logged in to upload." | ||
end | ||
end | ||
|
||
def new | ||
@image = Image.new() | ||
end | ||
|
||
def update | ||
if current_user && current_user.username == "warren" | ||
@image = Image.find params[:id] | ||
# make changes | ||
if @image.save | ||
flash[:notice] = "Image updated." | ||
else | ||
flash[:error] = "The image could not be updated." | ||
end | ||
redirect_to "/profile/"+@image.user.username | ||
else | ||
prompt_login "You must be logged in to edit images." | ||
end | ||
end | ||
|
||
def delete | ||
if current_user && current_user.username == "warren" | ||
@image = Image.find params[:id] | ||
if @image.uid == current_user.uid # or current_user.role == "admin" | ||
if @image.delete | ||
flash[:notice] = "Image deleted." | ||
else | ||
flash[:error] = "The image could not be deleted." | ||
end | ||
redirect_to "/profile/"+@image.user.username | ||
else | ||
prompt_login "Only the owner can delete this image." | ||
end | ||
else | ||
prompt_login "You must be logged in to delete images." | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
class Image < ActiveRecord::Base | ||
attr_accessible :uid, :notes, :title, :photo, :nid | ||
|
||
#has_many :comments, :dependent => :destroy | ||
#has_many :likes, :dependent => :destroy | ||
#has_many :tags, :dependent => :destroy | ||
has_one :user, :foreign_key => :uid | ||
has_one :node, :foreign_key => :nid | ||
|
||
has_attached_file :photo, :styles => { :small => "150x150>", :medium => "500x375>", :large => "800x600>" }, | ||
:url => "/assets/products/:id/:style/:basename.:extension", | ||
:path => ":rails_root/public/assets/products/:id/:style/:basename.:extension" | ||
|
||
validates :uid, :presence => :true | ||
validates :photo, :presence => :true | ||
validates :title, :presence => :true, :format => {:with => /\A[a-zA-Z0-9\ -_]+\z/, :message => "Only letters, numbers, and spaces allowed"}, :length => { :maximum => 60 } | ||
|
||
# Paperclip | ||
has_attached_file :photo, | ||
:styles => { | ||
:thumb=> "300x100!", | ||
:large => "800x200!" } | ||
|
||
has_attached_file :baseline, | ||
:styles => { | ||
:thumb=> "300x100!", | ||
:large => "800x200!" } | ||
|
||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<h2>Upload an image</h2> | ||
|
||
<%= form_for @image, :html => { :multipart => true } do |f| %> | ||
<%= f.error_messages %> | ||
|
||
<%= f.file_field :photo %> | ||
|
||
<p><%= f.text_field :title, {:placeholder => "Image title", :tabindex => 2} %></p> | ||
<p><%= f.text_field :notes, {:class => "span12", :placeholder => "a short description"} %></p> | ||
|
||
<p><button class="btn-large btn-primary" type="submit">Upload</button></p> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
class CreateImages < ActiveRecord::Migration | ||
def up | ||
create_table :images do |t| | ||
t.string :title | ||
t.integer :uid | ||
t.integer :nid | ||
t.string :notes | ||
t.integer :version, :default => 0 | ||
|
||
# attachment (paperclip) | ||
t.string :photo_file_name | ||
t.string :photo_content_type | ||
t.string :photo_file_size | ||
|
||
t.timestamps | ||
end | ||
end | ||
|
||
def down | ||
drop_table :images | ||
end | ||
end |
Empty file.