gpt4 book ai didi

mysql - rails、authlogic 和 sql 错误

转载 作者:行者123 更新时间:2023-11-30 23:36:48 25 4
gpt4 key购买 nike

我正在尝试使用 authlogic 在 rails 中使用 admin_name 和密码构建身份验证系统。我收到以下错误:

Mysql::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') = '[admin_name]') LIMIT 1' at line 1: SELECT admins.* FROM admins WHERE (LOWER(admins.) = '[admin_name]') LIMIT 1

这是 admin_session_controller.rb 中的代码...

def login
@admin_session = AdminSession.new(params[:admin_session])
if @admin_session.save
flash[:notice] = 'Successfuly logged in.'
redirect_to :controller => 'admins', :action => 'email_stats'
else
flash[:notice] = 'Trouble!!'
render :action => 'new'
end
end

我猜它不喜欢 params[:admin_session],但我真的不知道为什么。

erb 模板....

    <%= render :partial => 'layouts/head_admins' %>

<div id="notice">
<% if flash[:notice] %>
<%= flash[:notice] %>
<% end %>
</div>

<div id="main" align="middle">
<table>
<%= form_for @admin_session, :as => :admin_session, :url => { :action => "login" } do |f| %>
<tr class="bold gray">Admin_name</tr>
<tr id="login_admin_name"><%= f.text_field :admin_name, :class => "text", :tabindex => "1" %></tr>
<tr class="bold gray">Password</tr>
<tr id="login_password"><%= f.password_field :password, :class => "password", :tabindex => "2" %></tr>
<tr><%= image_submit_tag("login_btn.png", :id => 'login_btn', :class=>"image", :tabindex => "3", :alt => 'Login') %></tr>
<tr class="gray"><%= f.check_box :remember_me %>Keep me logged in</tr>
<% end %>
</table>
</div>

这是错误日志:

    Started POST "/admin_session/login" for 127.0.0.1 at 2011-07-17 19:58:07 -0700
Processing by AdminSessionController#login as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"[token]", "admin_session"=>{"admin_name"=>"[admin_name]", "password"=>"[FILTERED]"}, "x"=>"35", "y"=>"14"}
[1m[36mAdmin Load (136.4ms)[0m [1mSELECT `admins`.* FROM `admins` WHERE (LOWER(`admins`.) = '[admin_name]') LIMIT 1[0m
Mysql::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') = '[admin_name]') LIMIT 1' at line 1: SELECT `admins`.* FROM `admins` WHERE (LOWER(`admins`.) = '[admin_name]') LIMIT 1
Completed in 563ms

ActiveRecord::StatementInvalid (Mysql::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') = '[admin_name]') LIMIT 1' at line 1: SELECT `admins`.* FROM `admins` WHERE (LOWER(`admins`.) = '[admin_name]') LIMIT 1):
app/controllers/admin_session_controller.rb:18:in `login'

Rendered /home/tm/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.0.3/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.8ms)
Rendered /home/tm/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.0.3/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (6.7m

这是完整的轨迹......

 activerecord (3.0.3) lib/active_record/connection_adapters/abstract_adapter.rb:202:in `rescue in log'
activerecord (3.0.3) lib/active_record/connection_adapters/abstract_adapter.rb:194:in `log'
activerecord (3.0.3) lib/active_record/connection_adapters/mysql_adapter.rb:289:in `execute'
activerecord (3.0.3) lib/active_record/connection_adapters/mysql_adapter.rb:619:in `select'
activerecord (3.0.3) lib/active_record/connection_adapters/abstract/database_statements.rb:7:in `select_all'
activerecord (3.0.3) lib/active_record/connection_adapters/abstract/query_cache.rb:54:in `block in select_all'
activerecord (3.0.3) lib/active_record/connection_adapters/abstract/query_cache.rb:68:in `cache_sql'
activerecord (3.0.3) lib/active_record/connection_adapters/abstract/query_cache.rb:54:in `select_all'
activerecord (3.0.3) lib/active_record/base.rb:467:in `find_by_sql'
activerecord (3.0.3) lib/active_record/relation.rb:64:in `to_a'
activerecord (3.0.3) lib/active_record/relation/finder_methods.rb:333:in `find_first'
activerecord (3.0.3) lib/active_record/relation/finder_methods.rb:122:in `first'
activerecord (3.0.3) lib/active_record/relation/finder_methods.rb:119:in `first'
activerecord (3.0.3) lib/active_record/base.rb:439:in `first'
/home/tm/.rvm/gems/ruby-1.9.2-p180/bundler/gems/authlogic-a087ad0cba3c/lib/authlogic/acts_as_authentic/login.rb:121:in `find_with_case'
/home/tm/.rvm/gems/ruby-1.9.2-p180/bundler/gems/authlogic-a087ad0cba3c/lib/authlogic/acts_as_authentic/login.rb:112:in `find_by_smart_case_login_field'
/home/tm/.rvm/gems/ruby-1.9.2-p180/bundler/gems/authlogic-a087ad0cba3c/lib/authlogic/session/scopes.rb:95:in `block in search_for_record'
activerecord (3.0.3) lib/active_record/base.rb:1121:in `with_scope'
/home/tm/.rvm/gems/ruby-1.9.2-p180/bundler/gems/authlogic-a087ad0cba3c/lib/authlogic/session/scopes.rb:94:in `search_for_record'
/home/tm/.rvm/gems/ruby-1.9.2-p180/bundler/gems/authlogic-a087ad0cba3c/lib/authlogic/session/password.rb:183:in `validate_by_password'
activesupport (3.0.3) lib/active_support/callbacks.rb:415:in `_run_validate_callbacks'
activesupport (3.0.3) lib/active_support/callbacks.rb:93:in `run_callbacks'
/home/tm/.rvm/gems/ruby-1.9.2-p180/bundler/gems/authlogic-a087ad0cba3c/lib/authlogic/session/callbacks.rb:87:in `validate'
/home/tm/.rvm/gems/ruby-1.9.2-p180/bundler/gems/authlogic-a087ad0cba3c/lib/authlogic/session/validation.rb:64:in `valid?'
/home/tm/.rvm/gems/ruby-1.9.2-p180/bundler/gems/authlogic-a087ad0cba3c/lib/authlogic/session/existence.rb:65:in `save'
app/controllers/admin_session_controller.rb:19:in `login'
actionpack (3.0.3) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (3.0.3) lib/abstract_controller/base.rb:151:in `process_action'
actionpack (3.0.3) lib/action_controller/metal/rendering.rb:11:in `process_action'
actionpack (3.0.3) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (3.0.3) lib/active_support/callbacks.rb:445:in `_run__640502527__process_action__573632350__callbacks'
activesupport (3.0.3) lib/active_support/callbacks.rb:409:in `_run_process_action_callbacks'
activesupport (3.0.3) lib/active_support/callbacks.rb:93:in `run_callbacks'
actionpack (3.0.3) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.0.3) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
activesupport (3.0.3) lib/active_support/notifications.rb:52:in `block in instrument'
activesupport (3.0.3) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (3.0.3) lib/active_support/notifications.rb:52:in `instrument'
actionpack (3.0.3) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (3.0.3) lib/action_controller/metal/rescue.rb:17:in `process_action'
actionpack (3.0.3) lib/abstract_controller/base.rb:120:in `process'
actionpack (3.0.3) lib/abstract_controller/rendering.rb:40:in `process'
actionpack (3.0.3) lib/action_controller/metal.rb:138:in `dispatch'
actionpack (3.0.3) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.0.3) lib/action_controller/metal.rb:178:in `block in action'
actionpack (3.0.3) lib/action_dispatch/routing/route_set.rb:62:in `call'
actionpack (3.0.3) lib/action_dispatch/routing/route_set.rb:62:in `dispatch'
actionpack (3.0.3) lib/action_dispatch/routing/route_set.rb:27:in `call'
rack-mount (0.6.13) lib/rack/mount/route_set.rb:148:in `block in call'
rack-mount (0.6.13) lib/rack/mount/code_generation.rb:93:in `block in recognize'
rack-mount (0.6.13) lib/rack/mount/code_generation.rb:68:in `optimized_each'
rack-mount (0.6.13) lib/rack/mount/code_generation.rb:92:in `recognize'
rack-mount (0.6.13) lib/rack/mount/route_set.rb:139:in `call'
actionpack (3.0.3) lib/action_dispatch/routing/route_set.rb:492:in `call'
actionpack (3.0.3) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
actionpack (3.0.3) lib/action_dispatch/middleware/head.rb:14:in `call'
rack (1.2.1) lib/rack/methodoverride.rb:24:in `call'
actionpack (3.0.3) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.0.3) lib/action_dispatch/middleware/flash.rb:182:in `call'
actionpack (3.0.3) lib/action_dispatch/middleware/session/abstract_store.rb:149:in `call'
actionpack (3.0.3) lib/action_dispatch/middleware/cookies.rb:295:in `call'
activerecord (3.0.3) lib/active_record/query_cache.rb:32:in `block in call'
activerecord (3.0.3) lib/active_record/connection_adapters/abstract/query_cache.rb:28:in `cache'
activerecord (3.0.3) lib/active_record/query_cache.rb:12:in `cache'
activerecord (3.0.3) lib/active_record/query_cache.rb:31:in `call'
activerecord (3.0.3) lib/active_record/connection_adapters/abstract/connection_pool.rb:353:in `call'
actionpack (3.0.3) lib/action_dispatch/middleware/callbacks.rb:46:in `block in call'
activesupport (3.0.3) lib/active_support/callbacks.rb:415:in `_run_call_callbacks'
actionpack (3.0.3) lib/action_dispatch/middleware/callbacks.rb:44:in `call'
rack (1.2.1) lib/rack/sendfile.rb:107:in `call'
actionpack (3.0.3) lib/action_dispatch/middleware/remote_ip.rb:48:in `call'
actionpack (3.0.3) lib/action_dispatch/middleware/show_exceptions.rb:46:in `call'
railties (3.0.3) lib/rails/rack/logger.rb:13:in `call'
rack (1.2.1) lib/rack/runtime.rb:17:in `call'
activesupport (3.0.3) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.2.1) lib/rack/lock.rb:11:in `block in call'
<internal:prelude>:10:in `synchronize'
rack (1.2.1) lib/rack/lock.rb:11:in `call'
actionpack (3.0.3) lib/action_dispatch/middleware/static.rb:30:in `call'
railties (3.0.3) lib/rails/application.rb:168:in `call'
railties (3.0.3) lib/rails/application.rb:77:in `method_missing'
railties (3.0.3) lib/rails/rack/log_tailer.rb:14:in `call'
rack (1.2.1) lib/rack/content_length.rb:13:in `call'
rack (1.2.1) lib/rack/chunked.rb:15:in `call'
rack (1.2.1) lib/rack/handler/mongrel.rb:67:in `process'
mongrel (1.2.0.pre2) lib/mongrel.rb:165:in `block in process_client'
mongrel (1.2.0.pre2) lib/mongrel.rb:164:in `each'
mongrel (1.2.0.pre2) lib/mongrel.rb:164:in `process_client'
mongrel (1.2.0.pre2) lib/mongrel.rb:291:in `block (2 levels) in run'

谢谢...

最佳答案

我假设您并没有真正在文本字段中键入“[admin_name]”,而是调整了您向我们展示的日志?

您是在告诉 Authlogic 登录字段使用什么字段吗?除非它是默认值之一,否则这可能会解释为什么生成的 SQL 不包含要比较的实际列名...

SELECT `admins`.* FROM `admins` WHERE (LOWER(`admins`.) = '[admin_name]')

关于mysql - rails、authlogic 和 sql 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6728519/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com