class CreateSimpleCaptchaData < ActiveRecord::Migration
def self.up
create_table :simple_captcha_data do |t|
t.string :key, :limit => 40
t.string :value, :limit => 6
t.timestamps
end
add_index :simple_captcha_data, :key, :name => "idx_key"
end
def self.down
drop_table :simple_captcha_data
end
end
以上这段代码是不是通过 Migration 创建了一个名为 simple_captcha_data 的数据库表啊 其中包含两个字段,一个 string 类型的名为 key 长度为 40 的字段,另一个 string 类型的名为 value 长度为 6 的字段?
还有一个名为"idx_key"的表索引呢。
是这个意思么?
idx_key
只是给索引取一个名字而已,如果不要 :name 参数的话,Rails 会自动用前面的 :simple_captcha_data
和 :key
来组合索引名字 ,并且在前面加上 index_
也就是:index_simple_captcha_data_key
, 此外 MySQL 里面对于索引名称长度是有限制的
@huacnlee 想请教你一下关于 simple_captcha 的问题,为什么我按照官方的方法来操作,结果还是显示不出来呢。我想办法上传一下图片和错误信息吧
Started GET "/reg" for 127.0.0.1 at 2012-05-03 17:48:00 +0800
Processing by RegController#index as HTML
[1m[36mConfigs Load (0.2ms)[0m [1mSELECT content FROM `configs` WHERE `configs`.`describe` = 'site_title' LIMIT 1[0m
Rendered layouts/_header.html.erb (0.5ms)
Rendered reg/_styleb.html.erb (31.8ms)
[1m[35mSimpleCaptcha::SimpleCaptchaData Load (0.2ms)[0m SELECT `simple_captcha_data`.* FROM `simple_captcha_data` WHERE `simple_captcha_data`.`key` = '5c841c772de0825801882ceb1edf32f0a9492b7c' LIMIT 1
[1m[36m (0.1ms)[0m [1mBEGIN[0m
[1m[35mSQL (0.2ms)[0m INSERT INTO `simple_captcha_data` (`key`, `value`) VALUES ('5c841c772de0825801882ceb1edf32f0a9492b7c', 'SUFOVY')
[1m[36m (0.6ms)[0m [1mCOMMIT[0m
Rendered simple_captcha/_simple_captcha.erb (0.5ms)
Rendered reg/index.html.erb within layouts/application (69.4ms)
[1m[35mConfigs Load (0.2ms)[0m SELECT content FROM `configs` WHERE `configs`.`describe` = 'site_title' LIMIT 1
Rendered layouts/_header.html.erb (0.0ms)
Rendered layouts/_footer.html.erb (0.3ms)
Completed 200 OK in 90ms (Views: 82.7ms | ActiveRecord: 7.5ms)
Started GET "/simple_captcha?code=5c841c772de0825801882ceb1edf32f0a9492b7c&time=1336038481" for 127.0.0.1 at 2012-05-03 17:48:01 +0800
[1m[36mSimpleCaptcha::SimpleCaptchaData Load (0.3ms)[0m [1mSELECT `simple_captcha_data`.* FROM `simple_captcha_data` WHERE `simple_captcha_data`.`key` = '5c841c772de0825801882ceb1edf32f0a9492b7c' LIMIT 1[0m
[1m[35mCACHE (0.0ms)[0m SELECT `simple_captcha_data`.* FROM `simple_captcha_data` WHERE `simple_captcha_data`.`key` = '5c841c772de0825801882ceb1edf32f0a9492b7c' LIMIT 1
StandardError (Error while running convert: sh: convert: command not found
):
vendor/plugins/simple-captcha/lib/simple_captcha/utils.rb:17:in `run'
galetahub-simple_captcha (0.1.3) lib/simple_captcha/image.rb:76:in `generate_simple_captcha_image'
galetahub-simple_captcha (0.1.3) lib/simple_captcha/middleware.rb:36:in `make_image'
galetahub-simple_captcha (0.1.3) lib/simple_captcha/middleware.rb:18:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
rack (1.4.1) lib/rack/etag.rb:23:in `call'
rack (1.4.1) lib/rack/conditionalget.rb:25:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/head.rb:14:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/flash.rb:242:in `call'
rack (1.4.1) lib/rack/session/abstract/id.rb:205:in `context'
rack (1.4.1) lib/rack/session/abstract/id.rb:200:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/cookies.rb:338:in `call'
activerecord (3.2.3) lib/active_record/query_cache.rb:64:in `call'
activerecord (3.2.3) lib/active_record/connection_adapters/abstract/connection_pool.rb:467:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
activesupport (3.2.3) lib/active_support/callbacks.rb:405:in `_run__212775280641935933__call__3618682115726309637__callbacks'
activesupport (3.2.3) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.3) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
activesupport (3.2.3) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.3) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/reloader.rb:65:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
railties (3.2.3) lib/rails/rack/logger.rb:26:in `call_app'
railties (3.2.3) lib/rails/rack/logger.rb:16:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/request_id.rb:22:in `call'
rack (1.4.1) lib/rack/methodoverride.rb:21:in `call'
rack (1.4.1) lib/rack/runtime.rb:17:in `call'
activesupport (3.2.3) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.4.1) lib/rack/lock.rb:15:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/static.rb:62:in `call'
railties (3.2.3) lib/rails/engine.rb:479:in `call'
railties (3.2.3) lib/rails/application.rb:220:in `call'
rack (1.4.1) lib/rack/content_length.rb:14:in `call'
railties (3.2.3) lib/rails/rack/log_tailer.rb:14:in `call'
thin (1.3.1) lib/thin/connection.rb:80:in `block in pre_process'
thin (1.3.1) lib/thin/connection.rb:78:in `catch'
thin (1.3.1) lib/thin/connection.rb:78:in `pre_process'
thin (1.3.1) lib/thin/connection.rb:53:in `process'
thin (1.3.1) lib/thin/connection.rb:38:in `receive_data'
eventmachine (0.12.10) lib/eventmachine.rb:256:in `run_machine'
eventmachine (0.12.10) lib/eventmachine.rb:256:in `run'
thin (1.3.1) lib/thin/backends/base.rb:61:in `start'
thin (1.3.1) lib/thin/server.rb:159:in `start'
rack (1.4.1) lib/rack/handler/thin.rb:13:in `run'
rack (1.4.1) lib/rack/server.rb:265:in `start'
railties (3.2.3) lib/rails/commands/server.rb:70:in `start'
railties (3.2.3) lib/rails/commands.rb:55:in `block in <top (required)>'
railties (3.2.3) lib/rails/commands.rb:50:in `tap'
railties (3.2.3) lib/rails/commands.rb:50:in `<top (required)>'
script/rails:6:in `require'
script/rails:6:in `<top (required)>'
-e:1:in `load'
-e:1:in `<main>'
Rendered /Users/JasonJiang/.rvm/gems/ruby-1.9.3-p0/gems/actionpack-3.2.3/lib/action_dispatch/middleware/templates/rescues/_trace.erb (2.3ms)
Rendered /Users/JasonJiang/.rvm/gems/ruby-1.9.3-p0/gems/actionpack-3.2.3/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (1.1ms)
Rendered /Users/JasonJiang/.rvm/gems/ruby-1.9.3-p0/gems/actionpack-3.2.3/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (9.9ms)
我路由里是这样配置的
match ":controller(/:action)", :controller => /simple_captcha\/[^\/]+/
但是我原本使用的是 restful 路由呢,是不是我路由配错了啊?
没有找到 convert 这个 command,日志中已经非常明确的告诉你原因了。
这个命令来自 imagemagick,这个plugin在 githhub 的项目页的 Requirements 里面清晰的写着:ImageMagick should be installed on your machine to use this plugin. visit www.imagemagick.org/script/index.php for more details.
#16 楼 @xoxoj 这里的 log 就是你的最有效的支持信息,你应该坚定的以 log 作为解决问题的切入点。
我无法直接告诉你怎么做,但是我告诉你如果是我,我大概会怎么做:
generate_simple_captcha_image
这个行为你的这个问题应该是一个非常简单容易解决的问题,不过依赖你对 *nix
的基本知识的掌握。另外个人给你的建议是读 log 的时候应该非常仔细,在仔细,大部分问题都能通过 log 找到蛛丝马迹,时间长了你会非常喜欢通过 log 排查问题,而不是现在这样自己都不看,直接贴上来让大家帮你看。
@lgn21st 好的,感谢你的热心回复,耽误你很多时间了。我这个是一个测试例子,没有用 passenger,就是直接跑在 thin 下的,我会根据你的提示去努力解决问题的,非常感谢!