We have created a function to withdraw from Twitter login on Ruby on rails.If you click the withdrawal button, the following message will be displayed, but could you tell me how to deal with it?
Thank you for your cooperation.
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 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)device/sessions#new
user_session_path POST/users/sign_in(.:format)device/sessions#create
destroy_user_session_path DELETE/users/sign_out(.:format)device/sessions#destroy
user_omniauth_authorize_path GET|
POST/users/auth/:provider(.:format) users/omniauth_callbacks #pasthru {: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)device/passwords#create
new_user_password_path GET/users/password/new(.:format)device/passwords#new
edit_user_password_pathGET/users/password/edit(.:format)device/passwords#edit
PATCH/users/password(.:format) device/passwords# update
PUT/users/password(.:format) device/passwords# update
cancel_user_registration_path GET/users/cancel(.:format)device/registrations#cancel
user_registration_path POST/users(.:format)device/registrations#create
new_user_registration_path GET/users/sign_up(.:format)device/registrations#new
edit_user_registration_path GET/users/edit(.:format)device/registrations#edit
PATCH/users(.:format)device/registrations# update
PUT/users(.:format)device/registrations# update
DELETE/users(.:format)device/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
Parameters:
None Toggle session dump Toggle env dump Response
Headers:
None
app/users/users.controller.rb:
class UsersController<ApplicationController
before_action —Authenticate
defretire
end
def destroy
if current_user.destroy
reset_session
redirect_to root_path, notice: 'Departure completed'
else
render —retire
end
end
end
config/routes.rb:
Rails.application.routes.drawdo
resources:comments
device_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 with in anamespace:
# 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 device modules.Others available are:
# :confirmable, :lockable, :timeoutable and :mniauthable
device: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=Device.friendly_token [0,20]
end
end
private
def self.dummy_email(auth)
"#{auth.uid}-#{auth.provider}@e-xample.com"
end
end
NoMethodError occurs because the method name before_action has a full-width space in front of b and the method name blank before_action
.
Full-width characters can be used for basic method names, so you will get the same error as above.
I think it would be good to change the settings to make full-width spaces visible in Editor settings.
© 2024 OneMinuteCode. All rights reserved.