2014-03-28 88 views
0

我希望能够通过params更新记录。像这样的:如何通过params更新记录?

http://domain.com/api/v1/notes/2190/notify?message=test 

但它只是返回一个页面未找到。漂亮的标准路线回事:

resources :notes, only: [:show] do 
    post 'notify' 
end 

notify方法是这样的:

def notify 
    @note = Note.find(params[:id]) 
    if params[:message] 
    render text: @note.update_attributes(message: params[:message]) 
    end 
end 

我需要做别的允许此功能?任何建议呢?我无法弄清楚。干杯。

回答

1

的路线应该是这样的:

resources :notes, only: :show do 
    member do 
    get 'notify' 
    end 
end 
+0

仍然无法通过允许更新'卷曲--data'出于某种原因。 –

+0

@emm:你能用相应的curl命令更新你的问题吗? –

+0

它现在可以工作,但我不确定是什么让它工作,所以我要离开它。如果需要的话,仍可以更新它,但我认为这个问题确实超出了范围。因此我的投票结束它。 –