簡體   English   中英

在Rails 3中管理寧靜的資源

[英]Managing restful resources in Rails 3

我正在嘗試將Rails 2應用程序轉換為Rails 3,但是無法使用舊的Rails 2代碼刪除任何資源。 確切地說,我正在嘗試使用以下鏈接刪除資源:

<%= link_to image_tag("misc/delete.png"), @book, :confirm => 'Are you sure?', :method => :delete %>

但是它根本不起作用! 它的行為就像完全沒有設置:confirm選項和:method選項一樣,即,將我重定向到@book對象的url,甚至不顯示警告框。

在Rails 3中生成的HTML為:

<a href="/books/13" data-method="delete" rel="nofollow"><img alt="Delete" src="/images/misc/delete.png?1205252772"></a>

在Rails 2中生成的HTML是:

<a href="/books/11" class="small" onclick="if (confirm('Are you sure?')) { var f = document.createElement('form'); f.style.display = 'none'; this.parentNode.appendChild(f); f.method = 'POST'; f.action = this.href;var m = document.createElement('input'); m.setAttribute('type', 'hidden'); m.setAttribute('name', '_method'); m.setAttribute('value', 'delete'); f.appendChild(m);var s = document.createElement('input'); s.setAttribute('type', 'hidden'); s.setAttribute('name', 'authenticity_token'); s.setAttribute('value', 'uPeQI9FZxJT+DQlWvb02X5FEihG/hJgBk+vUhDwYT8o='); f.appendChild(s);f.submit(); };return false;"><img alt="Delete" src="/images/misc/delete.png?1279402305"></a> 

這是明顯的區別,但是我不知道該如何處理這個問題。

我的控制器看起來像這樣:

class BooksController < ApplicationController
  before_filter :require_admin, :only => ['new', 'create', 'edit', 'update', 'destroy']

  # ....

  def destroy
    puts "-------------- DESTROYING BOOK --------------"
    @book = Book.find(params[:id])
    @book.destroy

    flash[:notice] = "Successfully destroyed book."
    session[:restore] = request.referer
    redirect_to back(edit_author_url(@book.author))
  end
end

而且字符串“ destroying book”沒有顯示在控制台上,因此我認為肯定有問題。

我應該了解在Rails 3中對靜態處理的某些更改嗎?

多謝你們!

您需要添加rails javascript庫。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM