2010-01-09 74 views
1

在此先感謝。試圖提供儘可能多的細節。嘗試創建更新數據庫中布爾值記錄的鏈接。基本上,有人可以將禮物標記爲購買而無需另行訂購。我在過去通過發佈完成並刪除了沒有問題的鏈接。 :POST不是由控制器接受(僅爲什麼這個link_to url helper不更新布爾值記錄?

我得到: '禮品已成功更新。' 消息,點擊之後,但在數據庫沒有更新

<%= link_to "Mark Purchased", user_gift_path(@user, gift, :purchased => true), :method => :put %> 

控制器:採用InheritedResources寶石

class GiftsController < InheritedResources::Base 
    belongs_to :user 

    # redirects to gifts upon update 
    def update 
    update!{ collection_url } 
    end 

end 

工程在控制檯

>> g=Gift.last 
=> #<Gift id: 32, subject: "Birdbath", note: "Saw this at store ", created_at: "2010-01-09 18:52:48", updated_at: "2010-01-09 20:10:24", photo_file_name: "Birdbath.jpg", photo_content_type: "image/jpeg", photo_file_size: 7203, photo_updated_at: "2010-01-09 18:52:48", user_id: 18, store_id: 2, sku: "111390", product_url: "http://www.store.com/birdbath-kyoto-greensto...", price: 130.95, purchased: false, size_color: "blue"> 
>> g.purchased=true 
=> true 
>> g.save 
=> true 

服務器:

Processing GiftsController#update (for 127.0.0.1 at 2010-01-09 15:18:55) [PUT] 
    Parameters: {"authenticity_token"=>"***", "id"=>"32", "purchased"=>"true", "user_id"=>"18"} 
    User Columns (1.4ms) SHOW FIELDS FROM `users` 
    User Load (0.2ms) SELECT * FROM `users` WHERE (`users`.`id` = 18) 
    Gift Columns (1.2ms) SHOW FIELDS FROM `gifts` 
    Gift Load (0.2ms) SELECT * FROM `gifts` WHERE (`gifts`.`id` = 32 AND (`gifts`.user_id = 18)) 
    SQL (0.1ms) BEGIN 
    Store Columns (1.3ms) SHOW FIELDS FROM `stores` 
    Store Load (0.2ms) SELECT * FROM `stores` WHERE (`stores`.`id` = 2) 
[paperclip] Saving attachments. 
    SQL (0.1ms) COMMIT 
Redirected to http://localhost:3000/users/18/gifts 
Completed in 56ms (DB: 0) | 302 Found [http://localhost/users/18/gifts/32?purchased=true] 
    SQL (0.1ms) SET NAMES 'utf8' 
    SQL (0.1ms) SET SQL_AUTO_IS_NULL=0 


Processing GiftsController#index (for 127.0.0.1 at 2010-01-09 15:18:56) [GET] 
    Parameters: {"user_id"=>"18"} 
    User Columns (1.4ms) SHOW FIELDS FROM `users` 
    User Load (0.2ms) SELECT * FROM `users` WHERE (`users`.`id` = 18) 
    Gift Load (0.2ms) SELECT * FROM `gifts` WHERE (`gifts`.user_id = 18) 
Rendering template within layouts/application 
Rendering gifts/index 
    Gift Columns (1.3ms) SHOW FIELDS FROM `gifts` 
    Store Columns (1.2ms) SHOW FIELDS FROM `stores` 
    Store Load (0.2ms) SELECT * FROM `stores` WHERE (`stores`.`id` = 2) 
    User Load (0.3ms) SELECT * FROM `users` WHERE (`users`.`remember_token` = '***') LIMIT 1 
    CACHE (0.0ms) SELECT * FROM `stores` WHERE (`stores`.`id` = 2) 
    CACHE (0.0ms) SELECT * FROM `users` WHERE (`users`.`id` = 18) 
Completed in 65ms (View: 47, DB: 5) | 200 OK [http://localhost/users/18/gifts] 

回答

1

Doh!

<%= link_to "Mark Purchased", user_gift_path(@user, gift, :gift => {:purchased => true}), :method => :put %> 
相關問題