Connect plantings to photos.

This commit is contained in:
Miles Gould
2013-05-31 13:09:21 +01:00
parent c734f62189
commit e072883bb9
4 changed files with 23 additions and 1 deletions

View File

@@ -26,6 +26,7 @@ class PhotosController < ApplicationController
# GET /photos/new.json
def new
@photo = Photo.new
@planting_id = params[:planting_id]
@flickr_auth = current_member.auth('flickr')
if @flickr_auth
@@ -50,6 +51,12 @@ class PhotosController < ApplicationController
Photo.new(params[:photo])
@photo.owner_id = current_member.id
@photo.set_flickr_metadata
if params[:planting_id]
planting = Planting.find_by_id(params[:planting_id])
if planting
@photo.plantings << planting
end
end
respond_to do |format|
if @photo.save

View File

@@ -15,7 +15,7 @@
- c += 1
%li.span2
.thumbnail(style='height: 220px')
= link_to image_tag(FlickRaw.url_q(p), :alt => '', :class => 'img-rounded'), photos_path(:photo => { :flickr_photo_id => p.id }), :method => :post
= link_to image_tag(FlickRaw.url_q(p), :alt => '', :class => 'img-rounded'), photos_path(:photo => { :flickr_photo_id => p.id }, :planting_id => @planting_id), :method => :post
%p
=p.title
- if (c % 6) == 0

View File

@@ -51,6 +51,9 @@
- (1..6).each do
.span2
= image_tag('http://placehold.it/150x150', :alt => '', :class => 'img-rounded')
- if can? :create, Photo and can? :edit, @planting
%p
= link_to "Add photo", new_photo_path(:planting_id => @planting.id)
%h2
Notes

View File

@@ -51,6 +51,11 @@ describe PhotosController do
get :new, {}
assigns(:photo).should be_a_new(Photo)
end
it "assigns a planting id" do
get :new, { :planting_id => 5 }
assigns(:planting_id).should eq "5"
end
end
describe "GET edit" do
@@ -89,6 +94,13 @@ describe PhotosController do
post :create, {:photo => { :flickr_photo_id => 1 } }
response.should redirect_to(Photo.last)
end
it "attaches the photo to a planting" do
planting = FactoryGirl.create(:planting)
post :create, {:photo => { :flickr_photo_id => 1 },
:planting_id => planting.id }
Photo.last.plantings.first.should eq planting
end
end
describe "for the second time" do