テストアプリの1つでシナリオを複製し、公開済み(あなたの場合は確認済み)をtrueに設定できます。
移行
def up
create_table :posts do |t|
t.string :title
t.boolean :published, :default => false
t.string :token
t.timestamps
end
モデル
class Post < ActiveRecord::Base
attr_protected :published
before_create :generate_token
def generate_token
self.token = Time.now().to_i
end
end
コントローラ
class PostsController < ApplicationController
def publish
@post = Post.find_by_token(params[:token])
if !@post.published && params[:token] == @post.token # The second condition is not necessary in this case.
@post.published = true
@post.save
end
end
end
DBレコードフォームコンソールの作成
1.9.3-p0-perf :001 > p = Post.new({:title => "Protests against Violence"})
=> #<Post id: nil, title: "Protests against Violence", published: false, token: nil, created_at: nil, updated_at: nil>
1.9.3-p0-perf :002 > p.save
(0.2ms) BEGIN
SQL (7.3ms) INSERT INTO "posts" ("created_at", "published", "title", "token", "updated_at") VALUES ($1, $2, $3, $4, $5) RETURNING "id" [["created_at", Thu, 14 Feb 2013 07:41:58 UTC +00:00], ["published", false], ["title", "Protests against Violence"], ["token", 1360827718], ["updated_at", Thu, 14 Feb 2013 07:41:58 UTC +00:00]]
(7.5ms) COMMIT
=> true
1.9.3-p0-perf :003 > p.reload
Post Load (1.2ms) SELECT "posts".* FROM "posts" WHERE "posts"."id" = $1 LIMIT 1 [["id", 2]]
=> #<Post id: 2, title: "Protests against Violence", published: false, token: "1360827718", created_at: "2013-02-14 07:41:58", updated_at: "2013-02-14 07:41:58">
/ publish / 1360827718を押した後、コンソールからの出力は次のとおりです
#<Post id: 2, title: "Protests against Violence", published: true, token: "1360827718", created_at: "2013-02-14 07:41:58", updated_at: "2013-02-14 07:45:33">
このコードをpostgresql、rails 3.2.11、ruby 1.9.3で実行していて、コントローラーの公開アクションでpublished=trueが設定されています
問題を特定するのに役立たないコードと機能するコードを比較することがあり、それがこの回答の背後にある意図です。
これが問題の特定に役立つことを願っています。