Ruby on Rails路由错误 - Rails教程书第11章 - 关注/取消关注的问题

时间:2013-11-13 03:55:09

标签: ruby-on-rails ruby-on-rails-3 railstutorial.org

我完成了Rails Tutorial .org的第11章,并试图让'Follow'和'Unfollow'工作。当我点击其中任何一个按钮时,我得到的是以下错误:

Routing Error

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

以下是文件:

relationships_controller.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

的routes.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'

1 个答案:

答案 0 :(得分:3)

您的代码before filter(注意空格)应为before_filter