2010-10-05 54 views
0

這是我有我的觀點:如何使用link_to_remote更新Rails AR中的關聯(has_one)?

<%= link_to_remote "Responded - Positive", 
     :url => contact_path(@contact, :status => 'positive response'), 
     :update => "status" %> 

這是我的路線:

map.resources :contacts, :has_one => :status_contact 

以下是我在我的控制器使用:

def create 
    @status_contact = StatusContact.new(params[:status_contact]) 
    if @status_contact.save 
     #flash[:notice] = "Successfully created status contact." 
     #redirect_to @status_contact 
     render :text => "Set status to #{@status_contact.status}." 
    else 
     render :text => "bomb" 
    end 
    end 

我期望的結果是,對於特定的聯繫人,它將使用值「正面響應」更新Contact.status屬性,並通過ajax進行。

現在,我得到一個404錯誤。我需要做些什麼來糾正這個問題?

這是我仍然得到錯誤:

POST http://localhost:3000/contacts/24?method=put&status=positive+response 404 Not Found 
    312ms 
+0

今天要問很多問題,我們不是嗎? ;] – karlphillip 2010-10-05 04:51:40

+0

太多不知道:( – Angela 2010-10-05 16:13:04

回答

0

你可能用錯誤的動詞發送請求(:崗位而不是:放)。你想要控制你的控制器的哪個動作?這可能是更新操作...嘗試通過指定:put方法修改鏈接:

<%= link_to_remote "Responded - Positive", :url => contact_path(@contact, :status => 'positive response'), :method => :put, :update => "status" %> 
+0

酷,會嘗試 - 它會改變什麼,如果它是「關聯?」意思聯繫belongs_to一個status_contact表? – Angela 2010-10-05 16:14:02

+0

謝謝 - 這很奇怪 - 我沒有有這個問題之前,我改變了協會.....我會試試這個... – Angela 2010-10-06 00:04:06

+0

哦我記得,我想我有一個嵌套的路線....? – Angela 2010-10-06 00:05:35