简单使用 ActiveRecord 来做数据查询
class Tmnl < ActiveRecord::Base
set_table_name "tmnl_status"
#set_primary_key "STATUS_ID"
end
p Tmnl.first
但是这个表,不知特殊在哪里,其他表都没问题,总会在查询是报错:
ArgumentError: wrong number of arguments (1 for 0)
ArgumentError: wrong number of arguments (1 for 0)
__run_callback at /Users/santochan/.rvm/gems/jruby-1.6.7.2/gems/activesupport-3.2.8/lib/active_support/callbacks.rb:399
_run_find_callbacks at /Users/santochan/.rvm/gems/jruby-1.6.7.2/gems/activesupport-3.2.8/lib/active_support/callbacks.rb:390
__send__ at org/jruby/RubyBasicObject.java:1698
send at org/jruby/RubyKernel.java:2097
run_callbacks at /Users/santochan/.rvm/gems/jruby-1.6.7.2/gems/activesupport-3.2.8/lib/active_support/callbacks.rb:81
init_with at /Users/santochan/.rvm/gems/jruby-1.6.7.2/gems/activerecord-3.2.8/lib/active_record/base.rb:523
instantiate at /Users/santochan/.rvm/gems/jruby-1.6.7.2/gems/activerecord-3.2.8/lib/active_record/inheritance.rb:68
find_by_sql at /Users/santochan/.rvm/gems/jruby-1.6.7.2/gems/activerecord-3.2.8/lib/active_record/querying.rb:38
collect! at org/jruby/RubyArray.java:2363
find_by_sql at /Users/santochan/.rvm/gems/jruby-1.6.7.2/gems/activerecord-3.2.8/lib/active_record/querying.rb:38
logging_query_plan at /Users/santochan/.rvm/gems/jruby-1.6.7.2/gems/activerecord-3.2.8/lib/active_record/explain.rb:40
find_by_sql at /Users/santochan/.rvm/gems/jruby-1.6.7.2/gems/activerecord-3.2.8/lib/active_record/querying.rb:37
exec_queries at /Users/santochan/.rvm/gems/jruby-1.6.7.2/gems/activerecord-3.2.8/lib/active_record/relation.rb:171
to_a at /Users/santochan/.rvm/gems/jruby-1.6.7.2/gems/activerecord-3.2.8/lib/active_record/relation.rb:160
logging_query_plan at /Users/santochan/.rvm/gems/jruby-1.6.7.2/gems/activerecord-3.2.8/lib/active_record/explain.rb:40
to_a at /Users/santochan/.rvm/gems/jruby-1.6.7.2/gems/activerecord-3.2.8/lib/active_record/relation.rb:159
find_first at /Users/santochan/.rvm/gems/jruby-1.6.7.2/gems/activerecord-3.2.8/lib/active_record/relation/finder_methods.rb:378
first at /Users/santochan/.rvm/gems/jruby-1.6.7.2/gems/activerecord-3.2.8/lib/active_record/relation/finder_methods.rb:122
__send__ at org/jruby/RubyBasicObject.java:1698
send at org/jruby/RubyKernel.java:2097
find at /Users/santochan/.rvm/gems/jruby-1.6.7.2/gems/activerecord-3.2.8/lib/active_record/relation/finder_methods.rb:105
__send__ at org/jruby/RubyBasicObject.java:1704
find at /Users/santochan/.rvm/gems/jruby-1.6.7.2/gems/activerecord-3.2.8/lib/active_record/querying.rb:5
(root) at table_to_csv.rb:44
puts Tmnl.column_names
可以正常执行,得到:
status_id
cp_no
terminal_ip
terminal_mask
terminal_port
dial_no
machine_id_cur
machine_ip_cur
conn_time_cur
machine_id_prev
machine_ip_prev
conn_time_prev
send
receive
status
last_beat_time
refresh_time
terminal_id
area_code
status_code
protocol_code
run_date
type_code
manufacturer
coll_mode
rails3.2 开始就使用下列方法来设置 table name
self.table_name = "tmnl_status"
·set_table_name· 是 rails3.1 之前的方法
应该就是 send 这个字段,覆盖了 .send 方法了,要改名。
抛错的那行代码是
str = object.send("_#{kind}_callbacks").compile(key, object)
我搜了下,只搜到 activerecord-jdbc 有相关的问题,可能是 jruby 特有的?然后我新建了一个 app,用 send 字段没问题。
你试试不用 jruby,用 ruby 1.9.3。