Domanda

I am up to chapter 11 of Rails Tutorial .org and am trying to get the 'Follow' and 'Unfollow' to work. When I go to click on either of these buttons all I get is the following error:

Routing Error

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

Here are the files:

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'
È stato utile?

Soluzione

Your code says before filter (notice the space) when it should be before_filter.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top