From b42910636bb90ce5f9f8f30c4d0774f5f3e2f238 Mon Sep 17 00:00:00 2001 From: Espen Antonsen Date: Wed, 10 Jun 2009 01:22:48 +0200 Subject: [PATCH] readme. trying to get multiple objects in form --- README | 4 ++-- app/controllers/photos_controller.rb | 7 ++++--- app/views/photos/untouched.html.erb | 12 +++++++++++- app/views/photos/upload.html.erb | 1 + config/routes.rb | 4 ++-- 5 files changed, 20 insertions(+), 8 deletions(-) diff --git a/README b/README index 26569c6..8ddbff0 100644 --- a/README +++ b/README @@ -9,13 +9,13 @@ Made by Espen Antonsen * Read and writes EXIF * Organize in albums (events in iPhoto) * Combine albums in collections (albums in iPhoto) -* Upload multiple photos (using uploadify) +* Upload multiple photos * Tag photos. Can also tag albums (actually all photos in album is tagged) * User management with roles and permissions. == Requirements -Tested with Ruby 1.8.6 and Rails 2.3 +Rails 2.3 Software - FreeImage (required for Image_Science) diff --git a/app/controllers/photos_controller.rb b/app/controllers/photos_controller.rb index 4e72940..4bbaab1 100644 --- a/app/controllers/photos_controller.rb +++ b/app/controllers/photos_controller.rb @@ -98,9 +98,10 @@ class PhotosController < ApplicationController end def update_multiple - @photos = Photo.find(params[:photo_ids]) - @photos.each do |photo| - photo.update_attributes!(params[:photo].reject { |k,v| v.blank? }) + @photos = params[:photos][:photo] + @photos.each do |photo_id| + photo = Photo.find( photo_id ) + photo.update_attributes!(params[:photos][:photo][photo_id].reject { |k,v| v.blank? }) end flash[:notice] = "Updated photos!" redirect_to photos_path diff --git a/app/views/photos/untouched.html.erb b/app/views/photos/untouched.html.erb index b8c0f5c..2919768 100644 --- a/app/views/photos/untouched.html.erb +++ b/app/views/photos/untouched.html.erb @@ -1,3 +1,13 @@ - +<% form_for :photos, :url => update_multiple_photos_path, :html => { :method => :put } do |f| %> +<% for photo in @photos %> +

+<% f.fields_for photo do |p|%> + <%= p.text_field :title, :index => photo.id %> + <%= p.text_field :tags, :index => photo.id, :value => photo.tag_list %> +<% end%> +

+<% end%> +

<%= f.submit "Submit" %>

+<% end %>
<%= link_to "Back to #{@album.title}", @album %> \ No newline at end of file diff --git a/app/views/photos/upload.html.erb b/app/views/photos/upload.html.erb index 544683a..055a89d 100644 --- a/app/views/photos/upload.html.erb +++ b/app/views/photos/upload.html.erb @@ -34,4 +34,5 @@ $(document).ready(function() {
+
<%= link_to "Edit uploaded photos", untouched_album_photos_path( @album ) %>
<%= link_to "Back to #{@album.title}", @album %> \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 9b7390c..283a185 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -7,10 +7,10 @@ ActionController::Routing::Routes.draw do |map| map.resources :photos, :collection => { :untouched => :get, :edit_multiple => :post, :update_multiple => :put, :upload => :get } map.resources :albums, :collection => { :untouched => :get} do |album| - album.resources :photos, :collection => { :untouched => :get, :upload => :get, :edit_multiple => :get } + album.resources :photos, :collection => { :untouched => :get, :upload => :get, :edit_multiple => :get }, :shallow => true end map.resources :collections - map.resources :tags, :has_many => [ :photos, :albums ] + map.resources :tags, :has_many => [ :photos, :albums ], :shallow => true map.resources :users, :controller => "admin/users"