0

我的 rails 应用程序中有一个按钮,它生成一个带有图像和删除按钮的 div。当我单击删除时,我希望 div 被销毁并使用 ajax 消失。

html.erb:

<div class="button">
    <%= link_to "Generate Mockups",  { :controller => :ideas, :action => 
 :generate_mockups, remote: true, :id => idea.permalink} %>
  </div>
  <% idea.mockups.each do |mockup| %>
      <div class="idea-mockup <% if mockup.dirty %>dirty<% end %>">
    <h3><%= mockup.name %></h3>
    <p>
      <%= link_to "Delete", mockup_path(mockup), id: 'delete_mockups',  :method =>:delete, 
 :confirm => "Are you sure you want to delete this idea?",  :remote => true %>
    </p>
    <p>
      <%= link_to image_tag(mockup.file.url(:icon)), mockup.file.url, :target => "_blank", 
 :alt => mockup.description, :title => mockup.description %>
    </p>
    <% if mockup.dirty %>
        <p> The art or mockup template has been modified, and this mockup is being 
 recreated </p>
    <% end %>
  </div>
  <% end %>
</div>

想法控制器:

def generate_mockups
    @idea = Idea.find_by_permalink(params[:id])
    begin
      @idea.generate_mockups
    rescue Exception => e
     flash[:error] = "There was an error generating the mockups for #{@idea.working_name}! 
 #{e.message}"
    end
respond_to do |format|
  flash.now[:notice] = "Successfully generated mockups for #{@idea.working_name}"
  format.html {redirect_to idea_url(params[:id])}
  format.js
 end
 end

模型控制器:def destroy Mockup.find(params[:id]).destroy flash[:notice] = "模型被破坏。" redirect_to mockups_url 结束

当我单击 div 内的删除按钮时,我希望使用 ajax 销毁和隐藏模拟

4

0 回答 0