出于某种原因,当我删除上传的照片时,它所属的相册也会自动删除。
没有任何意义,因为我没有在任何模型上设置“依赖破坏”。
这是终端日志:
Started DELETE "/settings/photo_gallery/photos/86" for 127.0.0.1 at 2012-08-28 22:39:50 +0100
[af820895e0bf5c0b031bb5ea297290ee] [127.0.0.1] Processing by PhotosController#destroy as JS
[af820895e0bf5c0b031bb5ea297290ee] [127.0.0.1] Parameters: {"id"=>"86"}
[af820895e0bf5c0b031bb5ea297290ee] [127.0.0.1] Photo Load (0.4ms) SELECT `photos`.* FROM `photos` WHERE `photos`.`id` = 86 LIMIT 1
[af820895e0bf5c0b031bb5ea297290ee] [127.0.0.1] PhotoAlbum Load (0.2ms) SELECT `photo_albums`.* FROM `photo_albums` WHERE `photo_albums`.`photo_id` = 86 LIMIT 1
[af820895e0bf5c0b031bb5ea297290ee] [127.0.0.1] Profile Load (3.2ms) SELECT `profiles`.* FROM `profiles` WHERE `profiles`.`photo_id` = 86 LIMIT 1
[af820895e0bf5c0b031bb5ea297290ee] [127.0.0.1] (0.3ms) BEGIN
[af820895e0bf5c0b031bb5ea297290ee] [127.0.0.1] SQL (0.6ms) DELETE FROM `photos` WHERE `photos`.`id` = 86
[af820895e0bf5c0b031bb5ea297290ee] [127.0.0.1] (12.0ms) COMMIT
[af820895e0bf5c0b031bb5ea297290ee] [127.0.0.1] PhotoAlbum Load (15.2ms) SELECT `photo_albums`.* FROM `photo_albums` WHERE `photo_albums`.`id` = 36 LIMIT 1
[af820895e0bf5c0b031bb5ea297290ee] [127.0.0.1] Redirected to http://localhost:3000/settings/photo_gallery/36
[af820895e0bf5c0b031bb5ea297290ee] [127.0.0.1] Completed 302 Found in 46ms (ActiveRecord: 31.9ms)
[affa94ee1fa7dde2725d6f75c8cfb998] [127.0.0.1]
Started DELETE "/settings/photo_gallery/36" for 127.0.0.1 at 2012-08-28 22:39:50 +0100
[affa94ee1fa7dde2725d6f75c8cfb998] [127.0.0.1] Processing by PhotoAlbumsController#destroy as JS
[affa94ee1fa7dde2725d6f75c8cfb998] [127.0.0.1] Parameters: {"id"=>"36"}
[affa94ee1fa7dde2725d6f75c8cfb998] [127.0.0.1] PhotoAlbum Load (1.2ms) SELECT `photo_albums`.* FROM `photo_albums` WHERE `photo_albums`.`id` = 36 LIMIT 1
[affa94ee1fa7dde2725d6f75c8cfb998] [127.0.0.1] (0.1ms) BEGIN
[affa94ee1fa7dde2725d6f75c8cfb998] [127.0.0.1] SQL (0.3ms) DELETE FROM `photo_albums` WHERE `photo_albums`.`id` = 36
[affa94ee1fa7dde2725d6f75c8cfb998] [127.0.0.1] (4.6ms) COMMIT
[affa94ee1fa7dde2725d6f75c8cfb998] [127.0.0.1] Redirected to http://localhost:3000/settings/photo_gallery
[affa94ee1fa7dde2725d6f75c8cfb998] [127.0.0.1] Completed 302 Found in 22ms (ActiveRecord: 6.3ms)
[e5d66fa562a52440eb4e710bfc660402] [127.0.0.1]
相册型号:
class PhotoAlbum < ActiveRecord::Base
belongs_to :user
has_many :photos
belongs_to :photo
attr_accessible :album_title, :user_id, :photo_id
照片模型:
class Photo < ActiveRecord::Base
belongs_to :photo_album
attr_accessible :photo_album_id, :photo_title, :image, :remote_image_url, :banner_axis
mount_uploader :image, ImageUploader
用户显示视图:
<%= link_to "", @banner, :confirm => 'Are you sure?', :method => :delete, :remote => true %>
用户控制器显示操作:
def show
profile_banner_album_id = @user.photo_albums.find_by_album_title("profile banner").id
@banner = Photo.find_by_photo_album_id(profile_banner_album_id)
end
我已经离开铁轨一段时间了,所以有点生锈,所以我可能会遗漏一些非常明显的东西。查看日志,我不确定为什么在删除照片后会删除相册。
期待在这里得到一些帮助。亲切的问候