From af589525c9f907e3f83bfaed10ccff0c40c17096 Mon Sep 17 00:00:00 2001 From: Espen Antonsen Date: Thu, 18 Jun 2009 15:38:37 +0200 Subject: [PATCH] update multiple --- app/controllers/photos_controller.rb | 11 +++++++---- app/models/album.rb | 4 ++-- app/views/albums/_form.html.erb | 4 ++-- app/views/albums/show.html.erb | 2 +- app/views/collections/edit.html.erb | 3 ++- app/views/collections/new.html.erb | 4 +--- app/views/photos/edit_multiple.html.erb | 15 ++++++++++++++- config/routes.rb | 2 +- 8 files changed, 30 insertions(+), 15 deletions(-) diff --git a/app/controllers/photos_controller.rb b/app/controllers/photos_controller.rb index eb3e055..b49c267 100644 --- a/app/controllers/photos_controller.rb +++ b/app/controllers/photos_controller.rb @@ -86,7 +86,8 @@ class PhotosController < ApplicationController def edit_multiple if params[:album_id] - @photos = Album.find( params[:album_id] ).photos + @album = Album.find( params[:album_id] ) + @photos = @album.photos else @photos = Photo.find( params[:photo_ids] ) end @@ -104,9 +105,11 @@ class PhotosController < ApplicationController def update_multiple @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? }) + @photos.each do |photo_item| + photo = Photo.find( photo_item[0] ) + photo.title = photo_item[1][:title] + photo.tag_list = photo_item[1][:tags] + photo.save end flash[:notice] = "Updated photos!" redirect_to photos_path diff --git a/app/models/album.rb b/app/models/album.rb index 7ee3edf..12e9d44 100644 --- a/app/models/album.rb +++ b/app/models/album.rb @@ -57,8 +57,8 @@ class Album < ActiveRecord::Base def tags=(tags) tags = tags.split(" ").sort - return if tags == self.tag_list - current_tags = ( self.tag_list.nil? ? [] : self.tag_list.split(" ") ) + current_tags = ( self.tags.nil? ? [] : self.tags.split(" ") ) + return if tags == self.tags # find tags that should be removed from this album - thus remove from all photos in album # i.e. tags listed in self.tag_list but no in parameter tags diff --git a/app/views/albums/_form.html.erb b/app/views/albums/_form.html.erb index 726d75d..8cfa749 100644 --- a/app/views/albums/_form.html.erb +++ b/app/views/albums/_form.html.erb @@ -15,8 +15,8 @@ <%= form.label :note %>
<%= form.text_area :note %>
-<%= form.label :tag_list %>
-<%= form.text_field :tag_list, { :autocomplete => "off", :class => 'tag_list'} %>
+<%= form.label :tags %>
+<%= form.text_field :tags, { :autocomplete => "off", :class => 'tag_list'} %>

<% if @album.path? %> diff --git a/app/views/albums/show.html.erb b/app/views/albums/show.html.erb index 6dada79..b892544 100644 --- a/app/views/albums/show.html.erb +++ b/app/views/albums/show.html.erb @@ -13,7 +13,7 @@

<%= @album.description %>

-

Tagged with: <%= @album.tags.map {|tag| (link_to tag.title, tag_photos_path(tag) ) + " " } %>

+

Tagged with: <%= @album.tags.map {|tag| (link_to tag.title, tag_photos_path(tag) ) + " " } unless @album.tags.nil? %>

<% if has_role?("admin") %>

<%= @album.address %>

diff --git a/app/views/collections/edit.html.erb b/app/views/collections/edit.html.erb index 3f99e93..2d36f7e 100644 --- a/app/views/collections/edit.html.erb +++ b/app/views/collections/edit.html.erb @@ -6,7 +6,8 @@ <%= f.submit "Update" %> <% end %> +<% content_for :action_links do %>
<%= link_to("Delete this collection", { :action => "destroy", :id => @collection }, :confirm => "Are you sure you want to delete this collection?", :method => :delete) %> -
<%= link_to "All collections", collections_path %> \ No newline at end of file +<% end %> \ No newline at end of file diff --git a/app/views/collections/new.html.erb b/app/views/collections/new.html.erb index 46fa177..aeec19f 100644 --- a/app/views/collections/new.html.erb +++ b/app/views/collections/new.html.erb @@ -4,6 +4,4 @@ <%= f.error_messages %> <%= render :partial => "form", :object => f %> <%= f.submit "Create" %> -<% end %> - -
<%= link_to "All collections", collections_path %> \ No newline at end of file +<% end %> \ No newline at end of file diff --git a/app/views/photos/edit_multiple.html.erb b/app/views/photos/edit_multiple.html.erb index 3ab793f..27505a1 100644 --- a/app/views/photos/edit_multiple.html.erb +++ b/app/views/photos/edit_multiple.html.erb @@ -1 +1,14 @@ - \ No newline at end of file +<% form_for :photos, :url => update_multiple_photos_path, :html => { :method => :put } do |f| %> +<% for photo in @photos %> +

+<% f.fields_for photo do |p|%> + <%= render :partial => "photos/thumb", :locals => {:photo => photo } %> + <%= 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/config/routes.rb b/config/routes.rb index 9300ce1..a24bba9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -10,7 +10,7 @@ ActionController::Routing::Routes.draw do |map| end map.resources :collections do |collection| collection.resources :albums do |album| - album.resources :photos + album.resources :photos, :collection => { :untouched => :get } #album.resources :photos, :collection => { :untouched => :get, :upload => :get, :edit_multiple => :get } end end