update multiple

This commit is contained in:
Espen Antonsen 2009-06-18 15:38:37 +02:00
parent 7e418f9003
commit af589525c9
8 changed files with 30 additions and 15 deletions

View file

@ -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

View file

@ -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

View file

@ -15,8 +15,8 @@
<%= form.label :note %><br />
<%= form.text_area :note %><br />
<%= form.label :tag_list %><br />
<%= form.text_field :tag_list, { :autocomplete => "off", :class => 'tag_list'} %><br />
<%= form.label :tags %><br />
<%= form.text_field :tags, { :autocomplete => "off", :class => 'tag_list'} %><br />
<br />
<% if @album.path? %>

View file

@ -13,7 +13,7 @@
</div>
<p><%= @album.description %></p>
<p>Tagged with: <%= @album.tags.map {|tag| (link_to tag.title, tag_photos_path(tag) ) + " " } %></p>
<p>Tagged with: <%= @album.tags.map {|tag| (link_to tag.title, tag_photos_path(tag) ) + " " } unless @album.tags.nil? %></p>
<% if has_role?("admin") %>
<p><%= @album.address %></p>

View file

@ -6,7 +6,8 @@
<%= f.submit "Update" %>
<% end %>
<% content_for :action_links do %>
<br /><%= link_to("Delete this collection", { :action => "destroy", :id => @collection },
:confirm => "Are you sure you want to delete this collection?",
:method => :delete) %>
<br /><%= link_to "All collections", collections_path %>
<% end %>

View file

@ -4,6 +4,4 @@
<%= f.error_messages %>
<%= render :partial => "form", :object => f %>
<%= f.submit "Create" %>
<% end %>
<br /><%= link_to "All collections", collections_path %>
<% end %>

View file

@ -1 +1,14 @@
<ul><%= render :partial => @photos %></ul>
<% form_for :photos, :url => update_multiple_photos_path, :html => { :method => :put } do |f| %>
<% for photo in @photos %>
<p>
<% 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%>
</p>
<% end%>
<p><%= f.submit "Submit" %></p>
<% end %>
<br /><%= link_to "Back to #{@album.title}", @album %>

View file

@ -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