Commit 3a6723b9
Changed files (15)
app
assets
javascripts
stylesheets
controllers
helpers
views
creations
config
spec
controllers
helpers
views
app/assets/javascripts/photos.js.coffee
@@ -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/
app/assets/stylesheets/photos.css.scss
@@ -0,0 +1,3 @@
+// Place all the styles related to the Photos controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
app/controllers/photos_controller.rb
@@ -0,0 +1,32 @@
+class PhotosController < ApplicationController
+ before_filter :authenticate_user!
+ before_filter :find_creation
+ before_filter :find_or_build_photo
+
+ def create
+ respond_to do |format|
+ unless @photo.save
+ flash[:error] = "could not upload photo"
+ end
+ end
+ end
+
+ def destroy
+ respond_to do |format|
+ unless @photo.destroy
+ flash[:error] = "photo could not be deleted"
+ end
+ end
+ end
+
+ private
+ def find_creation
+ @creation = current_user.creations.find(params[:creation_id])
+ raise ActiveRecord::RecordNotFound unless @creation
+ end
+
+ def find_or_build_photo
+ @photo = params[:id] ? @creation.photos.find(params[:id]) : @creation.photos.build(params[:photo])
+ end
+
+end
app/helpers/photos_helper.rb
@@ -0,0 +1,2 @@
+module PhotosHelper
+end
app/views/creations/_form.html.erb
@@ -24,12 +24,14 @@
<%= f.file_field :image, :class => "input-file" %>
</div>
</div><!-- /clearfix -->
+ <!--
<div class="clearfix">
<%= f.label :remote_image_url, "Or Image URL" %><br />
<div class="input">
<%= f.text_field :remote_image_url, :class=>"xlarge" %>
</div>
- </div><!-- /clearfix -->
+ </div>
+ -->
<div class="clearfix">
<%= f.label :story %><br />
<div class="input">
app/views/creations/edit.html.erb
@@ -19,3 +19,17 @@
<%= render 'form' %>
</div>
</div>
+
+<div class="photo">
+ <%= render :partial => 'photos/photo', :collection => @creation.photos %>
+ <% unless @creation.new_record? %>
+ <%= form_tag(creation_photos_path(@creation), :method => "post", :multipart => true) do |f| %>
+ <%= fields_for Photo.new do |f| %>
+ <%= f.file_field :image, :rel => creation_photos_path(@creation) %>
+ <div class="actions">
+ <input type="submit" class="btn primary" value="Save changes"> <button type="reset" class="btn">Cancel</button>
+ </div>
+ <% end %>
+ <% end %>
+ <% end %>
+</div>
app/views/creations/show.html.erb
@@ -25,9 +25,14 @@
</div>
<div class="span4">
<ul class="media-grid">
+ <% @creation.photos.each do |photo| %>
+ <li> <a href=""><img class="thumbnail" src="<%= photo.image.thumb.url.to_s%>" alt="<%= photo.image %>"></a> </li>
+ <% end %>
+ <!--
<li> <a href=""><img class="thumbnail" src="<%= @creation.image.thumb.url.to_s%>" alt="<%= @creation.name %>"></a> </li>
<li> <a href=""><img class="thumbnail" src="<%= @creation.image.thumb.url.to_s%>" alt="<%= @creation.name %>"></a> </li>
<li> <a href=""><img class="thumbnail" src="<%= @creation.image.thumb.url.to_s%>" alt="<%= @creation.name %>"></a> </li>
+ -->
</ul>
</div>
</div>
app/views/photos/_photo.html.erb
@@ -0,0 +1,4 @@
+
+.photo[photo]
+ <%= image_tag photo.image_url(:thumb) if photo.image? %>
+ <%= link_to "Delete", creation_photo_path(@creation, photo), :method => :delete, :confirm => "Are you sure?" %>
app/views/photos/create.html.erb
@@ -0,0 +1,2 @@
+<h1>Photos#create</h1>
+<p>Find me in app/views/photos/create.html.erb</p>
app/views/photos/destroy.html.erb
@@ -0,0 +1,2 @@
+<h1>Photos#destroy</h1>
+<p>Find me in app/views/photos/destroy.html.erb</p>
config/routes.rb
@@ -5,7 +5,9 @@ Cake::Application.routes.draw do
get "home/index"
# /creations
- resources :creations
+ resources :creations do
+ resources :photos, :only => [:create, :destroy]
+ end
# /profiles
get "profiles/index"
spec/controllers/photos_controller_spec.rb
@@ -0,0 +1,19 @@
+require 'spec_helper'
+
+describe PhotosController do
+
+ describe "GET 'create'" do
+ it "returns http success" do
+ get 'create'
+ response.should be_success
+ end
+ end
+
+ describe "GET 'destroy'" do
+ it "returns http success" do
+ get 'destroy'
+ response.should be_success
+ end
+ end
+
+end
spec/helpers/photos_helper_spec.rb
@@ -0,0 +1,15 @@
+require 'spec_helper'
+
+# Specs in this file have access to a helper object that includes
+# the PhotosHelper. For example:
+#
+# describe PhotosHelper do
+# describe "string concat" do
+# it "concats two strings with spaces" do
+# helper.concat_strings("this","that").should == "this that"
+# end
+# end
+# end
+describe PhotosHelper do
+ pending "add some examples to (or delete) #{__FILE__}"
+end
spec/views/photos/create.html.erb_spec.rb
@@ -0,0 +1,5 @@
+require 'spec_helper'
+
+describe "photos/create.html.erb" do
+ pending "add some examples to (or delete) #{__FILE__}"
+end
spec/views/photos/destroy.html.erb_spec.rb
@@ -0,0 +1,5 @@
+require 'spec_helper'
+
+describe "photos/destroy.html.erb" do
+ pending "add some examples to (or delete) #{__FILE__}"
+end