嗨,我是 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();