undefined method ` before_action' のエラーが出る
前提・実現したいこと
Ruby on railsにてTwitterログインからの退会機能を作成しております。退会ボタンをおすと下記のメッセージが表示されてしまうのですが、対処方法をご教示頂けませんでしょうか?
何卒よろしくお願い致します。
発生している問題・エラーメッセージ
Routing Error
undefined method ` before_action' for UsersController:Class
Rails.root: /Users/TOMOAKI/photolog
Application Trace | Framework Trace | Full Trace app/controllers/users_controller.rb:2:in <class:UsersController>'
app/controllers/users_controller.rb:1:in <top (required)>' Routes
Routes match in priority from top to bottom
Helper HTTP Verb Path Controller#Action Path / Url Path Match
comments_path GET /comments(.:format) comments#index
POST /comments(.:format) comments#create
new_comment_path GET /comments/new(.:format) comments#new
edit_comment_path GET /comments/:id/edit(.:format) comments#edit
comment_path GET /comments/:id(.:format) comments#show
PATCH /comments/:id(.:format) comments#update
PUT /comments/:id(.:format) comments#update
DELETE /comments/:id(.:format) comments#destroy
new_user_session_path GET /users/sign_in(.:format) devise/sessions#new
user_session_path POST /users/sign_in(.:format) devise/sessions#create
destroy_user_session_path DELETE /users/sign_out(.:format) devise/sessions#destroy
user_omniauth_authorize_path GET|
POST /users/auth/:provider(.:format) users/omniauth_callbacks#passthru {:provider=>/twitter|facebook/}
user_omniauth_callback_path GET|
POST /users/auth/:action/callback(.:format) users/omniauth_callbacks#(?-mix:twitter|facebook)
user_password_path POST /users/password(.:format) devise/passwords#create
new_user_password_path GET /users/password/new(.:format) devise/passwords#new
edit_user_password_path GET /users/password/edit(.:format) devise/passwords#edit
PATCH /users/password(.:format) devise/passwords#update
PUT /users/password(.:format) devise/passwords#update
cancel_user_registration_path GET /users/cancel(.:format) devise/registrations#cancel
user_registration_path POST /users(.:format) devise/registrations#create
new_user_registration_path GET /users/sign_up(.:format) devise/registrations#new
edit_user_registration_path GET /users/edit(.:format) devise/registrations#edit
PATCH /users(.:format) devise/registrations#update
PUT /users(.:format) devise/registrations#update
DELETE /users(.:format) devise/registrations#destroy
root_path GET / redirect(301, /photos)
photos_path GET /photos(.:format) photos#index
POST /photos(.:format) photos#create
new_photo_path GET /photos/new(.:format) photos#new
edit_photo_path GET /photos/:id/edit(.:format) photos#edit
photo_path GET /photos/:id(.:format) photos#show
PATCH /photos/:id(.:format) photos#update
PUT /photos/:id(.:format) photos#update
DELETE /photos/:id(.:format) photos#destroy
retire_user_path GET /user/retire(.:format) users#retire
user_path POST /user(.:format) users#create
new_user_path GET /user/new(.:format) users#new
edit_user_path GET /user/edit(.:format) users#edit
GET /user(.:format) users#show
PATCH /user(.:format) users#update
PUT /user(.:format) users#update
DELETE /user(.:format) users#destroy
Request
Parameters:
None Toggle session dump Toggle env dump Response
Headers:
None
コード
app/users/users.contoller.rb:
class UsersController < ApplicationController
before_action :authenticate
def retire
end
def destroy
if current_user.destroy
reset_session
redirect_to root_path, notice:'退会完了しました'
else
render :retire
end
end
end
config/routes.rb:
Rails.application.routes.draw do
resources :comments
devise_for :users, controllers: { omniauth_callbacks: 'users/omniauth_callbacks' }
root to: redirect('/photos')
resources :photos
resource :user do
get 'retire'
end
# The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".
# You can have the root of your site routed with "root"
# root 'welcome#index'
# Example of regular route:
# get 'products/:id' => 'catalog#view'
# Example of named route that can be invoked with purchase_url(id: product.id)
# get 'products/:id/purchase' => 'catalog#purchase', as: :purchase
# Example resource route (maps HTTP verbs to controller actions automatically):
# resources :products
# Example resource route with options:
# resources :products do
# member do
# get 'short'
# post 'toggle'
# end
#
# collection do
# get 'sold'
# end
# end
# Example resource route with sub-resources:
# resources :products do
# resources :comments, :sales
# resource :seller
# end
# Example resource route with more complex sub-resources:
# resources :products do
# resources :comments
# resources :sales do
# get 'recent', on: :collection
# end
# end
# Example resource route with concerns:
# concern :toggleable do
# post 'toggle'
# end
# resources :posts, concerns: :toggleable
# resources :photos, concerns: :toggleable
# Example resource route within a namespace:
# namespace :admin do
# # Directs /admin/products/* to Admin::ProductsController
# # (app/controllers/admin/products_controller.rb)
# resources :products
# end
end
app/models/user.rb:
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable, :omniauthable
has_many :photos, dependent: :nullify
has_many :comments, dependent: :nullify
def self.find_or_create_from_oauth(auth)
User.find_or_create_by(provider: auth.provider, uid: auth.uid) do |user|
user.user_name = auth.info.nickname || auth.info.name
user.avatar_url = auth.info.image
user.email = User.dummy_email(auth)
user.password = Devise.friendly_token[0, 20]
end
end
private
def self.dummy_email(auth)
"#{auth.uid}-#{auth.provider}@example.com"
end
end