1

我已阅读 Rails Tutorial .org 的第 11 章,并试图让“关注”和“取消关注”工作。当我点击这些按钮中的任何一个时,我得到的只是以下错误:

Routing Error

undefined method `filter' for RelationshipsController:Class
Try running rake routes for more information on available routes.

以下是文件:

关系控制器.rb

class RelationshipsController < ApplicationController

    before filter :signed_in_user

    def create
        @user = User.find(params[:relationship][:followed_id])
        current_user.follow!(@user)
        redirect_to @user
    end

    def destroy
        @user = Relationship.find(params[:id]).followed
        current_user.unfollow!(@user)
        redirect_to @user
    end

end

路线.rb

  SampleApp::Application.routes.draw do

  resources :users do 
    member do
      get :following, :followers
    end
  end

  resources :sessions, only: [:new, :create, :destroy]
  resources :microposts, only: [:create, :destroy]
  resources :relationships, only: [:create, :destroy]

  root :to => 'static_pages#home'

  match '/help', to: "static_pages#help"

  match '/about', to: "static_pages#about"

  match '/contact', to: "static_pages#contact"

  match '/signup', to: 'users#new'
  match '/signin', to: 'sessions#new'
  match '/signout', to: 'sessions#destroy'
4

1 回答 1

3

您的代码说before filter(注意空格)应该是before_filter.

于 2013-11-13T03:56:48.857 回答