提前致谢。试图提供尽可能多的细节。尝试创建更新数据库中布尔记录的链接。基本上,有人可以在没有单独表格的情况下将礼物标记为已购买。我过去做过这一点,发布和删除链接没有问题。 :邮件未被控制器接受(仅
我得到:'礼物已成功更新。'单击后消息,但数据库未更新。
<%= link_to "Mark Purchased", user_gift_path(@user, gift, :purchased => true), :method => :put %>
Controller:使用InheritedResources Gem
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]
答案 0 :(得分:1)
卫生署!
<%= link_to "Mark Purchased", user_gift_path(@user, gift, :gift => {:purchased => true}), :method => :put %>