我使用的转换宝石创造在我的模型状态机设置像这样:查询由状态机状态的Rails 3
require 'transitions'
class Batch < ActiveRecord::Base
include Transitions
state_machine do
state :pending
state :completed
event :change_state do
transitions :to => :completed, :from => [:pending]
end
end
end
我要查询的模式来获取有所有的记录某些国家如:
Batch.where :current_state => :pending
但是,这似乎并没有工作,我无法在此找到文档。有谁知道如何做到这一点? (我相信这可能只是无法找到它)在此先感谢!
编辑
运行尾-n development.log给我:
ActionView::Template::Error (SQLite3::SQLException: no such column: batches.current_state: SELECT "batches".* FROM "batches" WHERE "batches"."user_id" = 1 AND "batches"."current_state" = 'pending'):
3: <%= link_to 'New Batch', new_batch_path %>
4:
5:
6: <% unless @pending_batches.length < 1 %>
7: You have <%= @pending_batches.length %> batches pending on these urls:
8: <% @pending_batches.each do |batch| %>
9: <%= batch.url %>
app/views/batches/index.html.erb:6:in `_app_views_batches_index_html_erb___355556540_17724200__911230187'
app/controllers/batches_controller.rb:8:in `index'
Rendered /Users/dshipper/.rvm/gems/[email protected]/gems/actionpack-3.0.9/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.5ms)
Batch Load (0.5ms) SELECT "batches".* FROM "batches" WHERE "batches"."user_id" = 1 AND "batches"."current_state" = 'pending'
SQLite3::SQLException: no such column: batches.current_state: SELECT "batches".* FROM "batches" WHERE "batches"."user_id" = 1 AND "batches"."current_state" = 'pending'
Rendered /Users/dshipper/.rvm/gems/[email protected]/gems/actionpack-3.0.9/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (6.6ms)
Rendered /Users/dshipper/.rvm/gems/[email protected]/gems/actionpack-3.0.9/lib/action_dispatch/middleware/templates/rescues/template_error.erb within rescues/layout (16.1ms)
SQL (0.2ms) SELECT name
FROM sqlite_master
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
Batch Load (0.3ms) SELECT "batches".* FROM "batches" HAVING "batches"."current_state" = 'pending'
SQLite3::SQLException: a GROUP BY clause is required before HAVING: SELECT "batches".* FROM "batches" HAVING "batches"."current_state" = 'pending'
运行的grep 'current_state DB/schema.rb' 返回任何结果。我期望,因为没有实际的列名为current_state,记录的状态由状态机管理(不确定它确切存储状态的位置)。
tail -n 500 development.log,grep'current_state db/schema.rb – Anatoly
该命令不起作用(我在Leopard上),但我将其更改为:tail -n 500 development.log | grep'current_state db/schema.rb'并且没有返回结果 – dshipper
这是两个不同的系统命令 – Anatoly