Commit 150450b9
Changed files (9)
app
assets
javascripts
stylesheets
controllers
models
views
app/assets/javascripts/application.js
@@ -6,4 +6,5 @@
//
//= require jquery
//= require jquery_ujs
+//= require jquery-ui
//= require_tree .
app/assets/javascripts/creations.js
@@ -0,0 +1,1 @@
+$(document).ready(function(){ });
app/assets/stylesheets/custom.css
@@ -1,1 +1,2 @@
.fright{float:right;}
+.hidden{display:none;}
app/controllers/photos_controller.rb
@@ -5,7 +5,9 @@ class PhotosController < ApplicationController
def create
respond_to do |format|
- unless @photo.save
+ if @photo.save
+ format.html { redirect_to(@creation, :notice => 'A new photo was added to the album.') }
+ else
flash[:error] = "could not upload photo"
end
end
@@ -13,7 +15,9 @@ class PhotosController < ApplicationController
def destroy
respond_to do |format|
- unless @photo.destroy
+ if @photo.destroy
+ format.html { redirect_to(@creation, :notice => 'A new photo was added to the album.') }
+ else
flash[:error] = "photo could not be deleted"
end
end
app/models/photo.rb
@@ -1,4 +1,5 @@
class Photo < ActiveRecord::Base
belongs_to :creation
+ validates :image, :presence => true
mount_uploader :image, PhotoUploader
end
app/views/creations/edit.html.erb
@@ -14,22 +14,30 @@
<%= image_tag @creation.image_url.to_s, :class => "thumbnail", :style => "width:235px;" %>
</a>
</div>
+
+ <% if @creation.photos.length < 3 %>
+ <% 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) %>
+ <input type="submit" class="btn primary" value="add another photo" />
+ <% end %>
+ <% end %>
+ <% end %>
+ <% end %>
+
</div>
<div class="span12">
<%= 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 %>
+<div class="row">
+ <div class="span1"> </div>
+ <% @creation.photos.each do |photo| %>
+ <div class="span5 media-grid">
+ <p><%= image_tag photo.image_url(:thumb) %></p>
+ <p><%= link_to "Delete »", creation_photo_path(@creation, photo), :class => 'btn', :method => :delete, :confirm => "Are you sure?" %></p>
+ </div>
<% end %>
</div>
app/views/creations/show.html.erb
@@ -28,11 +28,6 @@
<% @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>
@@ -65,3 +60,4 @@
<a href="<%= url_for profile_path @creation.user %>"><img src="<%= avatar_url @creation.user %>&s=200" alt="<%= @creation.user.name %>" /></a>
</div>
</div>
+
app/views/layouts/application.html.erb
@@ -3,7 +3,6 @@
<head>
<meta charset="utf-8">
<title><%= yield(:title) || "CakeSide" %></title>
- <title>Bootstrap, from Twitter</title>
<meta name="description" content="">
<meta name="author" content="">
<!--[if lt IE 9]>
app/views/photos/_photo.html.erb
@@ -1,4 +1,1 @@
-
-.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?" %>
+<li> <%= image_tag photo.image_url(:thumb) if photo.image? %> <%= link_to "Delete", creation_photo_path(@creation, photo), :method => :delete, :confirm => "Are you sure?" %> </li>