Your code says before filter
(notice the space) when it should be before_filter
.
Ruby on Rails Routing error - Rails Tutorial Book Chapter 11 - Issues with follow/ unfollow
-
30-07-2022 - |
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'
Soluzione
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow