8000
频繁刷新就会出现这个问题!
ActiveRecord::StatementInvalid in Reg#index
Showing /Users/WanKing/ror/TestSQL/app/views/reg/index.html.erb where line #45 raised:
Mysql2::Error: Unknown column 'simple_captcha_data.' in 'where clause': UPDATE simple_captcha_data
SET value
= 'QSAMEY' WHERE simple_captcha_data
.`` IS NULL
这个插件,没有刷新图片的功能,我写了一个刷新验证码的功能,可是刷新速度过快,或者次数频繁的话,就会出现这个错误!
"NetworkError: 500 Internal Server Error
@lgn21st 好的,感谢你的热心回复,耽误你很多时间了。我这个是一个测试例子,没有用 passenger,就是直接跑在 thin 下的,我会根据你的提示去努力解决问题的,非常感谢!
@lgn21st 权限已经有了,symlinked 也已经做好了,可是那个错误仍旧还在 :(
@lgn21st 你看看我的环境噢!
@lgn21st 可是我已经安装了 ImageMagick 了呀
我路由里是这样配置的
match ":controller(/:action)", :controller => /simple_captcha\/[^\/]+/
但是我原本使用的是 restful 路由呢,是不是我路由配错了啊?
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)
@huacnlee 想请教你一下关于 simple_captcha 的问题,为什么我按照官方的方法来操作,结果还是显示不出来呢。我想办法上传一下图片和错误信息吧
哈哈哈,谢谢大家了,另外大家有用过这个 simple_captcha 插件吗?我遇到了一些问题,想请教一下呢、
啊,应该是这个索引的名字?指的是什么啊!
@alice 是啊,我们网站可能就会遇到大并发的问题,那就没别的办法了吗?
搞定了!
还有一个问题就是,返回的数据是里,如果有中文的话,是这样的 city_cn":"\u4e0a\u6d77", 按理说,RAILS 应该是 UTF8 编码的啊,为什么这里又不显示成 UTF8 呢
现在解析出来的是这种格式:
[
{ "city_bm": "(shanghai)SH", "city_cn": "上海", "city_qp": "shanghai", "city_sx": "sh", "id": 1 }, { "city_bm": "(beijing)BJ", "city_cn": "北京", "city_qp": "beijing", "city_sx": "bj", "id": 2 } ]
我想要的是这种格式:
{ "1":[ "sh", "上海", "(shanghai)SH", "shanghai" ], "2":[ "bj", "北京", "(beijing)BJ", "beijing" ] }
[<%= raw @cities.map { |b| %{["#{b.id}","#{b.name}","#{b.value}"]} }.join(',') %>]
我试过用这种方式,定义 JSON 格式,可是没有效果啊!
还有一个问题请教一下,就是如何自定义返回 JSON 数据的格式结构啊!
@cantin 如果不加.json 后缀的话,不会出现 JSON 格式的页面,而是一个空白页面啊
@Rei 我现在是这样做的,我把这段 AJAX 内容,单独放在了一个 js 文件里,只在注册这个页面,才加载这个 js
$(function() { $ .ajax({ type : "post", url : "http://localhost:3000/jsoncities.json", timeout : 20000, error : function() { alert('服务器错误'); }, //contentType: "application/json", async : false, dataType : "json", success : function(data) { var str = ""; var str1 = "";
$("#reg-for-city").suggest(data, { hot_list : data, dataContainer : '#arrcity_3word', attachObject : '#suggest' }); }}); });
然后,我新建了一个 jsoncities 的 Controller,内容如下
class JsoncitiesController < ApplicationController
respond_to :json
def index @cities = Jsoncities.all respond_with(@cities) end
end
然后再设定了路由:
resources :jsoncities
这个时候,我可以通过http://localhost:3000/jsoncities.jsonJSON格式数据了。按理说,这个时候,我在JS里面调用这个地址,可以正常访问了啊访问到从数据库返回的
url : "http://localhost:3000/jsoncities.json",
可是还是出现这个错误
POST http://localhost:3000/jsoncities.json 404 Not Found
"NetworkError: 404 Not Found - http://localhost:3000/jsoncities.json"
@Rei 好的,感谢你的回复,我先查查 respond_to 这个东东!
@cantin 我上面这段是传统的 JS 方式啊。有没有在 RAILS 是用这种传统的方式写的啊?
@geekontheway 能介绍为什么用这两个的原因吗?
谢谢啦
@alice 这个好像很容易被撞破?!
搞定了,谢谢大家!
好的,谢谢提醒!
@huacnlee second.html.erb 单独调用?怎么个操作法啊!谢谢
补充一下,可能我描述的不够清楚,例如共有 3 个 scss(a.scss b.scss c.scss),有两个页面 first.html.erb second.html.erb 如果是默认的方式加载 scss 的话,first.html.erb 和 second.html.erb 都会包含 a.scss,b.scss,c.scss 这 3 个样式,可是我 second.html.erb 里不需要 b.scss 这个样式呢。