完全耗尽了我的所有脑力。我正在使用设计来管理rails 4应用程序中的用户。我有两个部分的应用程序。管理员方和用户方。
在Admin端销毁会话工作正常但用户方正在调用GET而不是DELETE。
以下是一些代码:
布局/ discover.html.erb
<%= stylesheet_link_tag "user/discover_application", media: "all"%>
<%= javascript_include_tag 'user/discover_application' %>
<%= csrf_meta_tag %>
布局/发现/ _modal.html.erb
<% if current_user %>
<li><%= link_to(raw('<i class="fa fa-sign-out"></i> Logout'), destroy_user_session_path, :method => "delete")%></li>
<% else %>
<li><%= link_to raw('<i class="fa fa-sign-in"></i> Login'), new_user_session_path%></li>
<% end %>
资产/ Javascript角/用户/ discover_application.js
//= require user/modernizr
//= require jquery
//= require jquery_ujs
路由
devise_for :users, :controllers => {:registrations => "registrations", :sessions => "sessions"}
resources :users
root :to => "discover#index"
我在管理方面几乎完全相同,它正常工作,所以我完全迷失了。没有javascript错误,rails渲染的标记将数据方法显示为删除。任何帮助都非常感谢。
已更新
Rails生成的实际链接
<a data-method="delete" href="/users/sign_out" rel="nofollow"><i class="fa fa-sign-out"></i> Logout</a>
日志:
Started GET "/users/sign_out" for 127.0.0.1 at 2014-06-22 22:22:16 -0500
Processing by UsersController#show as HTML
Parameters: {"id"=>"sign_out"}
Geokit is using the domain: localhost
User Load (0.7ms) SELECT "users".* FROM "users" WHERE "users"."id" = 2 ORDER BY "users"."id" ASC LIMIT 1
User Load (0.5ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1 [["id", "sign_out"]]
Completed 404 Not Found in 52ms
ActiveRecord::RecordNotFound - Couldn't find User with id=sign_out:
() Users/niknjegovan/.rvm/gems/ruby-2.1.1@global/gems/activerecord-4.0.3/lib/active_record/relation/finder_methods.rb:198:in `raise_record_not_found_exception!'
() Users/niknjegovan/.rvm/gems/ruby-2.1.1@global/gems/activerecord-4.0.3/lib/active_record/relation/finder_methods.rb:284:in `find_one'
() Users/niknjegovan/.rvm/gems/ruby-2.1.1@global/gems/activerecord-4.0.3/lib/active_record/relation/finder_methods.rb:268:in `find_with_ids'
() Users/niknjegovan/.rvm/gems/ruby-2.1.1@global/gems/activerecord-4.0.3/lib/active_record/relation/finder_methods.rb:35:in `find'
activerecord-deprecated_finders (1.0.3) lib/active_record/deprecated_finders/relation.rb:122:in `find'
() Users/niknjegovan/.rvm/gems/ruby-2.1.1@global/gems/activerecord-4.0.3/lib/active_record/querying.rb:3:in `find'
app/controllers/users_controller.rb:10:in `show'
() Users/niknjegovan/.rvm/gems/ruby-2.1.1@global/gems/actionpack-4.0.3/lib/action_controller/metal/implicit_render.rb:4:in `send_action'
() Users/niknjegovan/.rvm/gems/ruby-2.1.1@global/gems/actionpack-4.0.3/lib/abstract_controller/base.rb:189:in `process_action'
() Users/niknjegovan/.rvm/gems/ruby-2.1.1@global/gems/actionpack-4.0.3/lib/action_controller/metal/rendering.rb:10:in `process_action'
() Users/niknjegovan/.rvm/gems/ruby-2.1.1@global/gems/actionpack-4.0.3/lib/abstract_controller/callbacks.rb:18:in `block in process_action'
() Users/niknjegovan/.rvm/gems/ruby-2.1.1@global/gems/activesupport-4.0.3/lib/active_support/callbacks.rb:423:in `_run__1114563881307914935__process_action__callbacks'
() Users/niknjegovan/.rvm/gems/ruby-2.1.1@global/gems/activesupport-4.0.3/lib/active_support/callbacks.rb:80:in `run_callbacks'
() Users/niknjegovan/.rvm/gems/ruby-2.1.1@global/gems/actionpack-4.0.3/lib/abstract_controller/callbacks.rb:17:in `process_action'
() Users/niknjegovan/.rvm/gems/ruby-2.1.1@global/gems/actionpack-4.0.3/lib/action_controller/metal/rescue.rb:29:in `process_action'
() Users/niknjegovan/.rvm/gems/ruby-2.1.1@global/gems/actionpack-4.0.3/lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
() Users/niknjegovan/.rvm/gems/ruby-2.1.1@global/gems/activesupport-4.0.3/lib/active_support/notifications.rb:159:in `block in instrument'
() Users/niknjegovan/.rvm/gems/ruby-2.1.1@global/gems/activesupport-4.0.3/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
() Users/niknjegovan/.rvm/gems/ruby-2.1.1@global/gems/activesupport-4.0.3/lib/active_support/notifications.rb:159:in `instrument'
() Users/niknjegovan/.rvm/gems/ruby-2.1.1@global/gems/actionpack-4.0.3/lib/action_controller/metal/instrumentation.rb:30:in `process_action'
() Users/niknjegovan/.rvm/gems/ruby-2.1.1@global/gems/actionpack-4.0.3/lib/action_controller/metal/params_wrapper.rb:245:in `process_action'
() Users/niknjegovan/.rvm/gems/ruby-2.1.1@global/gems/activerecord-4.0.3/lib/active_record/railties/controller_runtime.rb:18:in `process_action'
() Users/niknjegovan/.rvm/gems/ruby-2.1.1@global/gems/actionpack-4.0.3/lib/abstract_controller/base.rb:136:in `process'
() Users/niknjegovan/.rvm/gems/ruby-2.1.1@global/gems/actionpack-4.0.3/lib/abstract_controller/rendering.rb:44:in `process'
() Users/niknjegovan/.rvm/gems/ruby-2.1.1@global/gems/actionpack-4.0.3/lib/action_controller/metal.rb:195:in `dispatch'
() Users/niknjegovan/.rvm/gems/ruby-2.1.1@global/gems/actionpack-4.0.3/lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
() Users/niknjegovan/.rvm/gems/ruby-2.1.1@global/gems/actionpack-4.0.3/lib/action_controller/metal.rb:231:in `block in action'
() Users/niknjegovan/.rvm/gems/ruby-2.1.1@global/gems/actionpack-4.0.3/lib/action_dispatch/routing/route_set.rb:80:in `call'
() Users/niknjegovan/.rvm/gems/ruby-2.1.1@global/gems/actionpack-4.0.3/lib/action_dispatch/routing/route_set.rb:80:in `dispatch'
() Users/niknjegovan/.rvm/gems/ruby-2.1.1@global/gems/actionpack-4.0.3/lib/action_dispatch/routing/route_set.rb:48:in `call'
() Users/niknjegovan/.rvm/gems/ruby-2.1.1@global/gems/actionpack-4.0.3/lib/action_dispatch/journey/router.rb:71:in `block in call'
() Users/niknjegovan/.rvm/gems/ruby-2.1.1@global/gems/actionpack-4.0.3/lib/action_dispatch/journey/router.rb:59:in `each'
() Users/niknjegovan/.rvm/gems/ruby-2.1.1@global/gems/actionpack-4.0.3/lib/action_dispatch/journey/router.rb:59:in `call'
() Users/niknjegovan/.rvm/gems/ruby-2.1.1@global/gems/actionpack-4.0.3/lib/action_dispatch/routing/route_set.rb:680:in `call'
warden (1.2.3) lib/warden/manager.rb:35:in `block in call'
warden (1.2.3) lib/warden/manager.rb:34:in `catch'
warden (1.2.3) lib/warden/manager.rb:34:in `call'
rack (1.5.2) lib/rack/etag.rb:23:in `call'
rack (1.5.2) lib/rack/conditionalget.rb:25:in `call'
rack (1.5.2) lib/rack/head.rb:11:in `call'
() Users/niknjegovan/.rvm/gems/ruby-2.1.1@global/gems/actionpack-4.0.3/lib/action_dispatch/middleware/params_parser.rb:27:in `call'
() Users/niknjegovan/.rvm/gems/ruby-2.1.1@global/gems/actionpack-4.0.3/lib/action_dispatch/middleware/flash.rb:241:in `call'
rack (1.5.2) lib/rack/session/abstract/id.rb:225:in `context'
rack (1.5.2) lib/rack/session/abstract/id.rb:220:in `call'
() Users/niknjegovan/.rvm/gems/ruby-2.1.1@global/gems/actionpack-4.0.3/lib/action_dispatch/middleware/cookies.rb:486:in `call'
() Users/niknjegovan/.rvm/gems/ruby-2.1.1@global/gems/activerecord-4.0.3/lib/active_record/query_cache.rb:36:in `call'
() Users/niknjegovan/.rvm/gems/ruby-2.1.1@global/gems/activerecord-4.0.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:626:in `call'
() Users/niknjegovan/.rvm/gems/ruby-2.1.1@global/gems/activerecord-4.0.3/lib/active_record/migration.rb:369:in `call'
() Users/niknjegovan/.rvm/gems/ruby-2.1.1@global/gems/actionpack-4.0.3/lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
() Users/niknjegovan/.rvm/gems/ruby-2.1.1@global/gems/activesupport-4.0.3/lib/active_support/callbacks.rb:373:in `_run__1405362911685491265__call__callbacks'
() Users/niknjegovan/.rvm/gems/ruby-2.1.1@global/gems/activesupport-4.0.3/lib/active_support/callbacks.rb:80:in `run_callbacks'
() Users/niknjegovan/.rvm/gems/ruby-2.1.1@global/gems/actionpack-4.0.3/lib/action_dispatch/middleware/callbacks.rb:27:in `call'
() Users/niknjegovan/.rvm/gems/ruby-2.1.1@global/gems/actionpack-4.0.3/lib/action_dispatch/middleware/reloader.rb:64:in `call'
() Users/niknjegovan/.rvm/gems/ruby-2.1.1@global/gems/actionpack-4.0.3/lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
better_errors (1.1.0) lib/better_errors/middleware.rb:84:in `protected_app_call'
better_errors (1.1.0) lib/better_errors/middleware.rb:79:in `better_errors_call'
better_errors (1.1.0) lib/better_errors/middleware.rb:56:in `call'
() Users/niknjegovan/.rvm/gems/ruby-2.1.1@global/gems/actionpack-4.0.3/lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
() Users/niknjegovan/.rvm/gems/ruby-2.1.1@global/gems/actionpack-4.0.3/lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
() Users/niknjegovan/.rvm/gems/ruby-2.1.1@global/gems/railties-4.0.3/lib/rails/rack/logger.rb:38:in `call_app'
() Users/niknjegovan/.rvm/gems/ruby-2.1.1@global/gems/railties-4.0.3/lib/rails/rack/logger.rb:20:in `block in call'
() Users/niknjegovan/.rvm/gems/ruby-2.1.1@global/gems/activesupport-4.0.3/lib/active_support/tagged_logging.rb:67:in `block in tagged'
() Users/niknjegovan/.rvm/gems/ruby-2.1.1@global/gems/activesupport-4.0.3/lib/active_support/tagged_logging.rb:25:in `tagged'
() Users/niknjegovan/.rvm/gems/ruby-2.1.1@global/gems/activesupport-4.0.3/lib/active_support/tagged_logging.rb:67:in `tagged'
() Users/niknjegovan/.rvm/gems/ruby-2.1.1@global/gems/railties-4.0.3/lib/rails/rack/logger.rb:20:in `call'
quiet_assets (1.0.2) lib/quiet_assets.rb:18:in `call_with_quiet_assets'
() Users/niknjegovan/.rvm/gems/ruby-2.1.1@global/gems/actionpack-4.0.3/lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
rack (1.5.2) lib/rack/runtime.rb:17:in `call'
() Users/niknjegovan/.rvm/gems/ruby-2.1.1@global/gems/activesupport-4.0.3/lib/active_support/cache/strategy/local_cache.rb:83:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
() Users/niknjegovan/.rvm/gems/ruby-2.1.1@global/gems/actionpack-4.0.3/lib/action_dispatch/middleware/static.rb:64:in `call'
rack (1.5.2) lib/rack/sendfile.rb:112:in `call'
() Users/niknjegovan/.rvm/gems/ruby-2.1.1@global/gems/railties-4.0.3/lib/rails/engine.rb:511:in `call'
() Users/niknjegovan/.rvm/gems/ruby-2.1.1@global/gems/railties-4.0.3/lib/rails/application.rb:97:in `call'
rack (1.5.2) lib/rack/content_length.rb:14:in `call'
thin (1.6.1) lib/thin/connection.rb:82:in `block in pre_process'
thin (1.6.1) lib/thin/connection.rb:80:in `catch'
thin (1.6.1) lib/thin/connection.rb:80:in `pre_process'
thin (1.6.1) lib/thin/connection.rb:55:in `process'
thin (1.6.1) lib/thin/connection.rb:41:in `receive_data'
eventmachine (1.0.3) lib/eventmachine.rb:187:in `run_machine'
eventmachine (1.0.3) lib/eventmachine.rb:187:in `run'
thin (1.6.1) lib/thin/backends/base.rb:73:in `start'
thin (1.6.1) lib/thin/server.rb:162:in `start'
rack (1.5.2) lib/rack/handler/thin.rb:16:in `run'
rack (1.5.2) lib/rack/server.rb:264:in `start'
() Users/niknjegovan/.rvm/gems/ruby-2.1.1@global/gems/railties-4.0.3/lib/rails/commands/server.rb:84:in `start'
() Users/niknjegovan/.rvm/gems/ruby-2.1.1@global/gems/railties-4.0.3/lib/rails/commands.rb:76:in `block in <top (required)>'
() Users/niknjegovan/.rvm/gems/ruby-2.1.1@global/gems/railties-4.0.3/lib/rails/commands.rb:71:in `tap'
() Users/niknjegovan/.rvm/gems/ruby-2.1.1@global/gems/railties-4.0.3/lib/rails/commands.rb:71:in `<top (required)>'
bin/rails:4:in `require'
bin/rails:4:in `<main>'
答案 0 :(得分:0)
是否有一些js拦截了自然的link_to(<a>
)行为?因为如果不是<a href>
总是GET请求。