質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Ruby on Rails 4

Ruby on Rails4はRubyによって書かれたオープンソースのウェブフレームワークです。 Ruby on Railsは「設定より規約」の原則に従っており、効率的に作業を行うために再開発を行う必要をなくしてくれます。

Q&A

0回答

2132閲覧

(Ruby on rails)Twitterログインからの退会機能でエラーが出てしまいます。

Tomoaki_Fukuda

総合スコア75

Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Ruby on Rails 4

Ruby on Rails4はRubyによって書かれたオープンソースのウェブフレームワークです。 Ruby on Railsは「設定より規約」の原則に従っており、効率的に作業を行うために再開発を行う必要をなくしてくれます。

0グッド

0クリップ

投稿2016/01/30 03:28

編集2016/01/30 03:29

###前提・実現したいこと
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

ruby

1class UsersController < ApplicationController 2 before_action :authenticate 3 4 def retire 5 end 6 7def destroy 8 if current_user.destroy 9 reset_session 10 redirect_to root_path, notice:'退会完了しました' 11 else 12 render :retire 13 end 14 end 15 16 17end 18

#config>routes.rb

ruby

1Rails.application.routes.draw do 2 resources :comments 3 devise_for :users, controllers: { omniauth_callbacks: 'users/omniauth_callbacks' } 4 root to: redirect('/photos') 5 resources :photos 6 resource :user do 7 get 'retire' 8 end 9 10 # The priority is based upon order of creation: first created -> highest priority. 11 # See how all your routes lay out with "rake routes". 12 13 # You can have the root of your site routed with "root" 14 # root 'welcome#index' 15 16 # Example of regular route: 17 # get 'products/:id' => 'catalog#view' 18 19 # Example of named route that can be invoked with purchase_url(id: product.id) 20 # get 'products/:id/purchase' => 'catalog#purchase', as: :purchase 21 22 # Example resource route (maps HTTP verbs to controller actions automatically): 23 # resources :products 24 25 # Example resource route with options: 26 # resources :products do 27 # member do 28 # get 'short' 29 # post 'toggle' 30 # end 31 # 32 # collection do 33 # get 'sold' 34 # end 35 # end 36 37 # Example resource route with sub-resources: 38 # resources :products do 39 # resources :comments, :sales 40 # resource :seller 41 # end 42 43 # Example resource route with more complex sub-resources: 44 # resources :products do 45 # resources :comments 46 # resources :sales do 47 # get 'recent', on: :collection 48 # end 49 # end 50 51 # Example resource route with concerns: 52 # concern :toggleable do 53 # post 'toggle' 54 # end 55 # resources :posts, concerns: :toggleable 56 # resources :photos, concerns: :toggleable 57 58 # Example resource route within a namespace: 59 # namespace :admin do 60 # # Directs /admin/products/* to Admin::ProductsController 61 # # (app/controllers/admin/products_controller.rb) 62 # resources :products 63 # end 64end 65

#app>models>user.rb

ruby

1class User < ActiveRecord::Base 2 # Include default devise modules. Others available are: 3 # :confirmable, :lockable, :timeoutable and :omniauthable 4 devise :database_authenticatable, :registerable, 5 :recoverable, :rememberable, :trackable, :validatable, :omniauthable 6 has_many :photos, dependent: :nullify 7 has_many :comments, dependent: :nullify 8 9 10 def self.find_or_create_from_oauth(auth) 11 User.find_or_create_by(provider: auth.provider, uid: auth.uid) do |user| 12 user.user_name = auth.info.nickname || auth.info.name 13 user.avatar_url = auth.info.image 14 user.email = User.dummy_email(auth) 15 user.password = Devise.friendly_token[0, 20] 16end 17end 18private 19 20def self.dummy_email(auth) 21"#{auth.uid}-#{auth.provider}@example.com" 22end 23 24end

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問