我的应用程序似乎无法找到我的会话控制器中的“摧毁”行动。 奇怪,因为它的存在。
我有像这样的链接:
<%= 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”, “检查”, “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 “” 罪 gleton_methods “ ”page_cache_extension“, ”认证“, ”new_user_url“, ”无?“, ”asset_host =“, ”应答“, ”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“, ”应答=“, ”hash_for_new_session_url“, ”断点“, ”格式=“, ”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“, ”存在“, ”头“, ”_view_paths?“, ”===“,” CLO NE”, “会话”, “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“, ”区域=“, ”hash_for_video_vote_url“, ”_helper_methods =“, ”instrument_fragment_cache“, ”edit_session_url“, ”过程“,” cache_store = “ ”_renderers“, ”的object_id“, ”video_votes_path“, ”_process_action_callbacks“, ”fragment_exist?“, ”as_json“, ”user_path“, ”的respond_to?“, ”_renderers =“, ”expires_in“,” 陈旧? “ ”render_to_facebox“, ”read_fragment“, ”videos_url“, ”acts_like?“, ”allow_concurrency“, ”hash_for_rails_info_properties_url“,” 模板 _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 =”, “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”, “缓存”, “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”, “负载”, “consider_all_requests_local”, “解除污染”, “users_path”, “render_to_string”, “尝试”, “ENV =”, “标题”, “hash_for_login_path”,“consider_all_request s_local = “ ”instance_of?“, ”view_runtime“, ”`“, ”require_association“, ”标题=“, ”hash_for_session_path“, ”SEND_DATA“, ”decode64“, ”new_video_path“, ”default_url_options?“,” view_runtime = ”, “_helpers?”, “记录”, “instance_values”, “要求”, “hash_for_users_url”, “冻结”, “stylesheets_dir”, “rescue_handlers?”, “login_path”, “记录器=”, “kind_of?”, “状态”, “hash_for_new_video_vote_path”, “stylesheets_dir =”, “响应”, “suppress_warnings”, “session_path”, “CONTROLLER_NAME”, “hash_for_new_video_url”, “状态=”, “controller路径”, “响应=”,“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”, “敲击”, “冻结?”, “new_video_url”,“_ helper_methods?”, “copy_instance_variables_from”, “url_for”, “警告”, “to_a”, “page_cache_directory”, “db_runtime =”, “闪”, “LOGIN_URL”, “rescue_action”, “page_cache_directory =”, “_handle_render_options” “polymorphic_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“, ”位置=“, ”散列“, ”authenticate_or_request_with_http_token“, ”initialize_template_class“, ”helpers_path =“,”请求=”, “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