2013-02-13 59 views
0

嗨我試圖從點擊事件遠程更新我的數據庫中的一個元素。 當點擊事件被觸發我收到以下錯誤,但我相信,我用正確的方法更新數據庫記錄與點擊事件

Started PUT "/availabilities/131/edit" for 124.168.74.144 at 2013-02-13 08:02:40 +0100 

ActionController::RoutingError (No route matches [PUT] "/availabilities/131/edit"): 

HAML點擊事件

.six.columns#named_players 


%h5 Named Players 
    %table.twelve 
    %thead 
     %tr 
     %th Change Status 
     %th Attending 
    %tbody 
     - @availabilities.each do |a| 
     %tr 
      %td= full_name(a.user) 
      %td 
      %ul.button-group.two-up.even 
       %li= button_to 'Accept', edit_availability_path(a), :remote => true, :method => :put, :class => 'button tiny success', :disable_with => 'Add' 
       %li= link_to 'Decline', '#', :remote => true, :method => :put, :class => 'button tiny alert' 

控制器

def update 
    @availability = Availability.find(params[:id]) 

    respond_to do |format| 
     if @availability.update_attributes(params[:availability]) 
     format.html { redirect_to @availability, :notice => 'Availability was successfully updated.' } 
     format.js 
     else 
     format.html { render :action => "edit" } 
     format.js 
     end 
    end 
    end 

回答

0

它你點擊[PUT] "/availabilities/131/edit"而不是[PUT] "/availabilities/131/update"

+0

所以我需要改變我的路線? – 2013-02-13 07:45:53

+0

你必須添加更新路由(如果它還不存在),並且你的按鈕(或鏈接)必須調用更新控制器方法 – 2013-02-13 07:54:09

+0

更新在我的控制器中已經如上所述,所以id需要更改鏈接? – 2013-02-13 08:05:37