您好我是rails的新手,我正在使用rails 3.我的是想要使用ajax从列表中删除图像。当我单击“删除”按钮时,图像仍然可以在索引页面上看到,但实际上它已被删除,但用户可以在刷新网页后看到更改。我希望它在ajax用于的同一页面上可见。任何人请帮忙。谢谢......
我的控制器代码是:
def destroy
logger.info params[:event].inspect
@event = Event.find(params[:id])
@event.destroy
#redirect_to events_url
respond_to do |format|
format.html { redirect_to @event, :notice => 'Event deleted' }
format.js
end
end
我的观点代码是:
**app/view/events/index.html.haml**
- @events.each do |event|
%ol.hoverbox
%li.all{:id =>"event_#{event.id}"}
= link_to image_tag(event.photo.url), event_path(event)
.abc
= event.name
%br/
.bca
= event.start_date
|
= event.start_time
|
= link_to " ".html_safe, event_path(event), :remote => true, :method => :delete, :class => "del-16", :confirm=>"Are u sure?", :title => "Delete", :style => "text-decoration:none;"
js的代码是:
*destroy.js.erb*
$("#event_#{event.id}").fadeOut().remove();
答案 0 :(得分:1)