Thanks in advance. Tried to provide as much detail as possible. Attempting to create a link that updates a boolean record in a database. Basically, someone can mark a gift as purchased without going a separate form. I've done this in the past with post and delete links without problems. :post not accepted by controller (only
I get: 'Gift was successfully updated.' message after clicking but the database is not updated.
<%= link_to "Mark Purchased", user_gift_path(@user, gift, :purchased => true), :method => :put %>
Controller: Uses InheritedResources Gem
class GiftsController < InheritedResources::Base
belongs_to :user
# redirects to gifts upon update
def update
update!{ collection_url }
end
end
Works in Console
>> 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
Server:
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]