找不到“毁灭”动作,但它就在那里......奇怪的错误

发布于 2024-10-26 04:23:50 字数 7829 浏览 2 评论 0原文

我的应用程序似乎无法在我的会话控制器中找到“销毁”操作。很奇怪,因为它就在那里。

我有一个像这样的链接:

<%= link_to "Logout", logout_path %>

我将其路由到 routes.rb 中的销毁操作:

match '/logout' => "sessions#destroy", :as => "logout"

这是我的会话控制器中的“销毁”操作:

def destroy
  reset_session
  redirect_to videos_path
end

当我单击该链接时,我收到此错误我的日志:

Started GET "/logout" for 127.0.0.1 at Thu Mar 24 02:58:36 -0700 2011

AbstractController::ActionNotFound (The action 'destroy' could not be found for SessionsController):

这里发生了什么?

更新:

这是我的routes.rb文件:

root :to => "videos#new"
resources :videos
resources :video_votes
resources :users
resource :session
match '/login' => "sessions#new", :as => "login"
match '/logout' => "sessions#destroy", :as => "logout"

SessionsController.instance_methods 的输出:

["protected_instance_variables", "asset_path", "hidden_​​actions?", "with_warnings", "inspect", "content_type", "new_polymorphic_url ", "authenticate_with_http_basic", "new_user_path", “details_for_lookup”、“allow_forgery_protection=”、“view_context”、“protected_instance_variables=”、“asset_path=”、“default_url_options”、“authenticate_with_http_token”、“id”、“content_type=”、“assign_shortcuts” 、“_routes”、“_save_fragment”、 “default_url_options =”,“hash_for_new_session_path”,“redirect_to_facebox”,“edit_video_path”,“_layout_conditions”,“enable_warnings”,“new_polymorphic_path”,“request_http_basic_authentication”,“hash_for_new_user_url”,“方法”,“append_view_path”, “request_http_token_authentication”,“hash_for_logout_path”,“hidden_​​actions”,“_layout_conditions =”,“发送”,“hash_for_edit_video_vote_path”,“handler_for_rescue”,“expire_action”,“new_session_path”,“hidden_​​actions =”,“宝石”, “caching_allowed?”,“hash_for_edit_video_url”,“asset_host”,“_renderers?”,“to_json”,“singleton_methods”,“page_cache_extension”,“authenticate”,“new_user_url”,“nil?”,“asset_host =”,“responder "、"logout_path"、"action_methods"、"格式"、 “prepend_view_path”,“edit_video_vote_path”,“_handle_method_missing”,“page_cache_extension =”,“_one_time_conditions_valid_16?”,“protect_against_forgery?”,“rescue_handlers”,“responder =”,“hash_for_new_session_url”,“断点”,“formats =”, “perform_caching”,“require_dependency”,“verify_authenticity_token”,“edit_video_url”,“to_yaml_properties”,“form_authenticity_token”,“rescue_handlers =”,“with_options”,“protected_methods”,“silence_stderr”,“perform_caching =”,“等于吗?” 、“可复制吗?”、 “hash_for_logout_url”,“mimes_for_respond_to”,“hash_for_edit_video_vote_url”,“_render_option_json”,“record_key_for_dom_id”,“class_eval”,“append_info_to_payload”,“new_session_url”,“mimes_for_respond_to =”,“回调”,“响应者?”, “private_methods”,“silence_stream”,“hash_for_edit_user_path”,“发送”,“hash_for_root_path”,“html_safe?”,“执行?”,“eql?”,“current_user”,“to_yaml”,“decode_b”,“logout_url” 、“id”、“edit_video_vote_url”、“_render_option_js”、 “verified_request?”,“sanitize_dom_id”,“hash_for_video_path”,“_render_template”,“handle_unverified_request”,“instance_eval”,“渲染”,“edit_user_path”,“public_methods”,“cache_page”,“hash_for_root_url”,“respond_to”,“类型”,“_render_option_xml”, “hash_for_edit_session_path”、“action_has_layout?”、“hash_for_video_url”、“mimes_for_respond_to?”、“翻译”、“instance_exec”、“hash_for_edit_user_url”、“抑制”、“instance_variables”、“空白?”、“hash_for_videos_path”、“method_for_action” , “b64encode”,“类”,“_render_option_update”,“url_options”,“hash_for_video_vote_path”,“singleton_class”,“lookup_context”,“edit_session_path”,“reset_session”,“video_url”,“可卸载”,“instance_variable_get”,“encode64 ”、“派遣”、“礼物?”、 “edit_user_url”、“videos_path”、“==”、“hash_for_rails_info_properties_path”、“存在”、“head”、“_view_paths?”、“===”、“克隆”、“会话”、“fresh_when”、“video_vote_path” ”、“_normalize_options”、“配置”、“find_template”、“view_context_class”、 “response_body”,“fragment_cache_key”,“hash_for_edit_session_url”,“form_authenticity_param”,“hash_for_video_votes_path”,“view_context_class =”,“logged_in?”,“调试器”,“instance_variable_set”,“response_body =”,“区域设置”, “authenticate_or_request_with_http_digest”,“hash_for_user_path”,“=~”,“_helper_methods”,“access_denied”,“hash_for_videos_url”,“创建”,“rails_info_properties_path”,“dup”,“cache_store”,“polymorphic_path”,“locale =”, “hash_for_video_vote_url”、“_helper_methods=”、“instrument_fragment_cache”、“edit_session_url”、“process”、“cache_store=”、“_renderers”、“object_id”、“video_votes_path”、“_process_action_callbacks”、“fragment_exist?”、“as_json” 、“用户路径”、“响应?”、 “_renderers =”,“expires_in”,“过时?”,“render_to_facebox”,“read_fragment”,“videos_url”,“acts_like?”,“allow_concurrency”,“hash_for_rails_info_properties_url”,“template_exists?”,“send_action”,“返回"、"污点"、"expires_now"、 “video_vote_url”,“t”,“assets_dir”,“view_paths”,“_helpers”,“allow_concurrency=”,“params”,“redirect_to”,“middleware_stack”,“to_enum”,“hash_for_video_votes_url”,“assets_dir=”, “实例变量_定义?”,“require_or_load”,“_prefix”, “_helpers =”,“params =”,“authenticate_with_http_digest”,“hash_for_user_url”,“middleware_stack =”,“dom_class”,“write_fragment”,“new_video”,“retrieve_response_from_mimes”,“_layout_conditions?”,“rails_info_properties_url”,“to_param “, “hash_for_users_path”、“javascripts_dir”、“缓存”、“root_url”、“扩展”、“新”、“enum_for”、“video_votes_url”、“javascripts_dir=”、“本地化”、“request_http_digest_authentication”、“user_url”、“ send_file", "dom_id", "被污染?", "通知", “hash_for_new_video_path”、“respond_with”、“env”、“to_query”、“load”、“consider_all_requests_local”、“untaint”、“users_path”、“render_to_string”、“try”、“env=”、“headers”、“ hash_for_login_path", "consider_all_requests_local=", "instance_of?", “view_runtime”,“`”,“require_association”,“headers =”,“hash_for_session_path”,“send_data”,“decode64”,“new_video_path”,“default_url_options?”,“view_runtime =”,“_helpers?”,“记录器"、"instance_values"、"require"、"hash_for_users_url"、"冻结"、 “stylesheets_dir”,“rescue_handlers?”,“login_path”,“logger =”,“kind_of?”,“状态”,“hash_for_new_video_vote_path”,“stylesheets_dir =”,“响应”,“suppress_warnings”,“session_path”,“controller_name” ”、“hash_for_new_video_url”、“状态=”、 “controller_path”,“response =”,“action_has_layout =”,“instance_variable_names”,“collect_mimes_from_class_level”,“users_url”,“l”,“edit_polymorphic_url”,“authenticate_or_request_with_http_basic”,“request_forgery_protection_token”,“render_to_body”, “run_callbacks”,“hash_for_login_url”,“video_path”,“is_a?”,“new_video_vote_path”,“方法”,“request_forgery_protection_token =”,“load_dependency”,“db_runtime”,“hash_for_session_url”,“tap”,“冻结?” 、“新视频网址”、 “_helper_methods?”,“copy_instance_variables_from”,“url_for”,“alert”,“to_a”,“page_cache_directory”,“db_runtime =”,“flash”,“login_url”,“rescue_action”,“page_cache_directory =”,“_handle_render_options” 、“多态_url”、 “hash_for_new_video_vote_url”,“显示”,“expire_fragment”,“taguri”,“cleanup_view_runtime”,“session_url”,“close_facebox”,“位置”,“default_render”,“to_s”,“silence_warnings”,“taguri =”,“ helpers_path”,“请求”,“edit_polymorphic_path”, “hash_for_new_user_path”,“action_name”,“_view_paths”,“location =”,“哈希”,“authenticate_or_request_with_http_token”,“initialize_template_class”,“helpers_path =”,“request =”,“new_video_vote_url”,“action_name =”,“_view_paths =”,“rescue_with_handler”, "require_library_or_gem", "expire_page", "to_yaml_style", "middleware_stack?", "redirect_from_facebox", "root_path", "allow_forgery_protection", "hash_for_edit_video_path"]

这是我的整个会话控制器:

class SessionsController < ApplicationController

  def create
    if user = User.authenticate(params[:email], params[:password])
      session[:user_id] = user.id
      redirect_to videos_path
    else
      flash.now[:alert] = "Invalid login/password combination"
      render :action => 'new'
    end

    def destroy
      reset_session
      redirect_to videos_path
    end
  end
end

My app can't seem to find the 'destroy' action in my Sessions controller. Weird, because it's there.

I have a link like so:

<%= link_to "Logout", logout_path %>

Which I route to my destroy action in routes.rb:

match '/logout' => "sessions#destroy", :as => "logout"

And here is the 'destroy' action in my sessions controller:

def destroy
  reset_session
  redirect_to videos_path
end

When I click the link, I get this error in my logs:

Started GET "/logout" for 127.0.0.1 at Thu Mar 24 02:58:36 -0700 2011

AbstractController::ActionNotFound (The action 'destroy' could not be found for SessionsController):

What's going on here?

UPDATE:

Here's my routes.rb file:

root :to => "videos#new"
resources :videos
resources :video_votes
resources :users
resource :session
match '/login' => "sessions#new", :as => "login"
match '/logout' => "sessions#destroy", :as => "logout"

Output of SessionsController.instance_methods:

["protected_instance_variables", "asset_path", "hidden_actions?", "with_warnings", "inspect", "content_type", "new_polymorphic_url", "authenticate_with_http_basic", "new_user_path", "details_for_lookup", "allow_forgery_protection=", "view_context", "protected_instance_variables=", "asset_path=", "default_url_options", "authenticate_with_http_token", "id", "content_type=", "assign_shortcuts", "_routes", "_save_fragment", "default_url_options=", "hash_for_new_session_path", "redirect_to_facebox", "edit_video_path", "_layout_conditions", "enable_warnings", "new_polymorphic_path", "request_http_basic_authentication", "hash_for_new_user_url", "methods", "append_view_path", "request_http_token_authentication", "hash_for_logout_path", "hidden_actions", "_layout_conditions=", "send", "hash_for_edit_video_vote_path", "handler_for_rescue", "expire_action", "new_session_path", "hidden_actions=", "gem", "caching_allowed?", "hash_for_edit_video_url", "asset_host", "_renderers?", "to_json", "singleton_methods", "page_cache_extension", "authenticate", "new_user_url", "nil?", "asset_host=", "responder", "logout_path", "action_methods", "formats", "prepend_view_path", "edit_video_vote_path", "_handle_method_missing", "page_cache_extension=", "_one_time_conditions_valid_16?", "protect_against_forgery?", "rescue_handlers", "responder=", "hash_for_new_session_url", "breakpoint", "formats=", "perform_caching", "require_dependency", "verify_authenticity_token", "edit_video_url", "to_yaml_properties", "form_authenticity_token", "rescue_handlers=", "with_options", "protected_methods", "silence_stderr", "perform_caching=", "equal?", "duplicable?", "hash_for_logout_url", "mimes_for_respond_to", "hash_for_edit_video_vote_url", "_render_option_json", "record_key_for_dom_id", "class_eval", "append_info_to_payload", "new_session_url", "mimes_for_respond_to=", "callback", "responder?", "private_methods", "silence_stream", "hash_for_edit_user_path", "send", "hash_for_root_path", "html_safe?", "performed?", "eql?", "current_user", "to_yaml", "decode_b", "logout_url", "id", "edit_video_vote_url", "_render_option_js", "verified_request?", "sanitize_dom_id", "hash_for_video_path", "_render_template", "handle_unverified_request", "instance_eval", "render", "edit_user_path", "public_methods", "cache_page", "hash_for_root_url", "respond_to", "type", "_render_option_xml", "hash_for_edit_session_path", "action_has_layout?", "hash_for_video_url", "mimes_for_respond_to?", "translate", "instance_exec", "hash_for_edit_user_url", "suppress", "instance_variables", "blank?", "hash_for_videos_path", "method_for_action", "b64encode", "class", "_render_option_update", "url_options", "hash_for_video_vote_path", "singleton_class", "lookup_context", "edit_session_path", "reset_session", "video_url", "unloadable", "instance_variable_get", "encode64", "dispatch", "present?", "edit_user_url", "videos_path", "==", "hash_for_rails_info_properties_path", "presence", "head", "_view_paths?", "===", "clone", "session", "fresh_when", "video_vote_path", "_normalize_options", "config", "find_template", "view_context_class", "response_body", "fragment_cache_key", "hash_for_edit_session_url", "form_authenticity_param", "hash_for_video_votes_path", "view_context_class=", "logged_in?", "debugger", "instance_variable_set", "response_body=", "locale", "authenticate_or_request_with_http_digest", "hash_for_user_path", "=~", "_helper_methods", "access_denied", "hash_for_videos_url", "create", "rails_info_properties_path", "dup", "cache_store", "polymorphic_path", "locale=", "hash_for_video_vote_url", "_helper_methods=", "instrument_fragment_cache", "edit_session_url", "process", "cache_store=", "_renderers", "object_id", "video_votes_path", "_process_action_callbacks", "fragment_exist?", "as_json", "user_path", "respond_to?", "_renderers=", "expires_in", "stale?", "render_to_facebox", "read_fragment", "videos_url", "acts_like?", "allow_concurrency", "hash_for_rails_info_properties_url", "template_exists?", "send_action", "returning", "taint", "expires_now", "video_vote_url", "t", "assets_dir", "view_paths", "_helpers", "allow_concurrency=", "params", "redirect_to", "middleware_stack", "to_enum", "hash_for_video_votes_url", "assets_dir=", "instance_variable_defined?", "require_or_load", "_prefix", "_helpers=", "params=", "authenticate_with_http_digest", "hash_for_user_url", "middleware_stack=", "dom_class", "write_fragment", "new_video", "retrieve_response_from_mimes", "_layout_conditions?", "rails_info_properties_url", "to_param", "hash_for_users_path", "javascripts_dir", "cache", "root_url", "extend", "new", "enum_for", "video_votes_url", "javascripts_dir=", "localize", "request_http_digest_authentication", "user_url", "send_file", "dom_id", "tainted?", "notice", "hash_for_new_video_path", "respond_with", "env", "to_query", "load", "consider_all_requests_local", "untaint", "users_path", "render_to_string", "try", "env=", "headers", "hash_for_login_path", "consider_all_requests_local=", "instance_of?", "view_runtime", "`", "require_association", "headers=", "hash_for_session_path", "send_data", "decode64", "new_video_path", "default_url_options?", "view_runtime=", "_helpers?", "logger", "instance_values", "require", "hash_for_users_url", "freeze", "stylesheets_dir", "rescue_handlers?", "login_path", "logger=", "kind_of?", "status", "hash_for_new_video_vote_path", "stylesheets_dir=", "response", "suppress_warnings", "session_path", "controller_name", "hash_for_new_video_url", "status=", "controller_path", "response=", "action_has_layout=", "instance_variable_names", "collect_mimes_from_class_level", "users_url", "l", "edit_polymorphic_url", "authenticate_or_request_with_http_basic", "request_forgery_protection_token", "render_to_body", "run_callbacks", "hash_for_login_url", "video_path", "is_a?", "new_video_vote_path", "method", "request_forgery_protection_token=", "load_dependency", "db_runtime", "hash_for_session_url", "tap", "frozen?", "new_video_url", "_helper_methods?", "copy_instance_variables_from", "url_for", "alert", "to_a", "page_cache_directory", "db_runtime=", "flash", "login_url", "rescue_action", "page_cache_directory=", "_handle_render_options", "polymorphic_url", "hash_for_new_video_vote_url", "display", "expire_fragment", "taguri", "cleanup_view_runtime", "session_url", "close_facebox", "location", "default_render", "to_s", "silence_warnings", "taguri=", "helpers_path", "request", "edit_polymorphic_path", "hash_for_new_user_path", "action_name", "_view_paths", "location=", "hash", "authenticate_or_request_with_http_token", "initialize_template_class", "helpers_path=", "request=", "new_video_vote_url", "action_name=", "_view_paths=", "rescue_with_handler", "require_library_or_gem", "expire_page", "to_yaml_style", "middleware_stack?", "redirect_from_facebox", "root_path", "allow_forgery_protection", "hash_for_edit_video_path"]

Here's my entire Sessions controller:

class SessionsController < ApplicationController

  def create
    if user = User.authenticate(params[:email], params[:password])
      session[:user_id] = user.id
      redirect_to videos_path
    else
      flash.now[:alert] = "Invalid login/password combination"
      render :action => 'new'
    end

    def destroy
      reset_session
      redirect_to videos_path
    end
  end
end

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

那伤。 2024-11-02 04:23:51

看起来我搞乱了 Sessions 控制器中 end 的位置,导致我的 destroy 方法无法工作...

我必须将 Sessions 控制器更改为:

class SessionsController < ApplicationController

def create
  if user = User.authenticate(params[:email], params[:password])
    session[:user_id] = user.id
    redirect_to videos_path
  else
    flash.now[:alert] = "Invalid login/password combination"
    render :action => 'new'
  end
end

  def destroy
    reset_session
    redirect_to videos_path
  end
end

It looks like I messed up the placement of end in my Sessions controller that was causing my destroy method to not work...

I had to change my Sessions controller to:

class SessionsController < ApplicationController

def create
  if user = User.authenticate(params[:email], params[:password])
    session[:user_id] = user.id
    redirect_to videos_path
  else
    flash.now[:alert] = "Invalid login/password combination"
    render :action => 'new'
  end
end

  def destroy
    reset_session
    redirect_to videos_path
  end
end
白况 2024-11-02 04:23:51

尝试更改这一行:

match '/logout' => "sessions#destroy", :as => "logout"

并使其看起来像这样:

get '/logout' => "sessions#destroy", :as => "logout"

它是相同的路线,但它只会响应获取此特定操作的请求。

Try to change this line :

match '/logout' => "sessions#destroy", :as => "logout"

and make it look like this one :

get '/logout' => "sessions#destroy", :as => "logout"

it's the same route but it will respond only to get request for this specific action.

可是我不能没有你 2024-11-02 04:23:51

好的,我想我明白了

将 paths.rb 更改为

resources :sessions

Ok I think I got it

Change routes.rb to

resources :sessions
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文