我有一个索引页面,如:
def index
@admin_albums = Admin::Album.unscoped
respond_to do |format|
format.html
format.json { render json: @admin_albums }
end
end
我也有一个销毁行动:
def destroy
@admin_album = Admin::Album.unscoped.find(params[:id])
@admin_album.destroy
respond_to do |format|
format.html { redirect_to admin_albums_path }
format.json { head :no_content }
end
end
索引视图:
<% @admin_albums.each do |admin_album| %>
<tr>
<td><%= admin_album.admin_style.nom %></td>
<td><%= admin_album.titre %></td>
<td><%= admin_album.artiste %></td>
<td><%= truncate(admin_album.critiques, :length => 255).html_safe %></td>
<td><%= oui_non(admin_album.public) %></td>
<td><%= link_to 'Voir', admin_album %></td>
<td><%= link_to 'Modifier', edit_admin_album_path(admin_album) %></td>
<td><%= link_to 'Supprimer', admin_album, method: :delete, data: { confirm: 'Êtes-vous sûr ?' } %></td>
</tr>
<% end %>
问题是:当我点击“Supprimer”时,为了删除一个条目,我被重定向到索引页面,并且该条目仍然出现在页面上。但它在数据库中被删除了! 怎么可能?
如果我刷新页面,那条目就在那里!我必须等待几分钟才能在索引页面上输入消失。
在日志中,似乎忽略了请求“Admin :: Album.unscoped.all”,您可以看到它:
Started GET "/admin/albums" for 127.0.0.1 at 2013-10-26 20:04:09 +0200
Processing by Admin::AlbumsController#index as HTML
[1m[36mAdmin::Couleurmenu Load (0.0ms)[0m [1mSELECT `admin_couleurmenus`.* FROM `admin_couleurmenus` ORDER BY `admin_couleurmenus`.`id` DESC LIMIT 1[0m
Rendered admin/albums/index.html.erb within layouts/admin (1.0ms)
Completed 200 OK in 55ms (Views: 54.0ms | ActiveRecord: 0.0ms)
编辑:破坏日志中的操作:
Started DELETE "/admin/albums/33" for 127.0.0.1 at 2013-10-26 20:04:09 +0200
Processing by Admin::AlbumsController#destroy as HTML
Parameters: {"authenticity_token"=>"b79G4x4m0X56OaRFskKkpLet67IzJfpGAPSsbK7U058=", "id"=>"33"}
[1m[35mAdmin::Couleurmenu Load (0.0ms)[0m SELECT `admin_couleurmenus`.* FROM `admin_couleurmenus` ORDER BY `admin_couleurmenus`.`id` DESC LIMIT 1
[1m[36mAdmin::Album Load (1.0ms)[0m [1mSELECT `admin_albums`.* FROM `admin_albums` WHERE `admin_albums`.`id` = 33 LIMIT 1[0m
[1m[35m (0.0ms)[0m BEGIN
[paperclip] Scheduling attachments for deletion.
[1m[36mSQL (13.0ms)[0m [1mDELETE FROM `admin_albums` WHERE `admin_albums`.`id` = 33[0m
[paperclip] Deleting attachments.
[paperclip] deleting C:/Ruby/ldp/public/system/admin/albums/pochettes/000/000/033/original/clap032_1440-1.jpg
[paperclip] deleting C:/Ruby/ldp/public/system/admin/albums/pochettes/000/000/033/medium/clap032_1440-1.jpg
[paperclip] deleting C:/Ruby/ldp/public/system/admin/albums/pochettes/000/000/033/thumb/clap032_1440-1.jpg
[1m[35m (1.0ms)[0m COMMIT
Redirected to http://localhost:3000/admin/albums
Completed 302 Found in 41ms (ActiveRecord: 15.0ms)
问题出在哪里?有人有想法吗?