ruby on railsを初めて1周間の者です。
ログイン機能を作りたく、検索する中でdeviseというものを見つけ、
なんとか動作するまでは作ることができました。
しかし、ログインした後にユーザー固有のマイページ(/users/1など)に飛ばしたく、苦戦しています。
検索すると、after_sign_in_path_forというメソッド?というのがあったので、
application_controller.rbは以下のようにしました。
ruby
1class ApplicationController < ActionController::Base 2 protect_from_forgery with: :exception 3 4 # ログイン後に遷移するページ 5 def after_sign_in_path_for(resource) 6 mypage(resource) 7 end 8 9end
しかし、コレだけではまだ足りないようで、ログインボタンを押すと、以下のエラーが出てしまいます。
NoMethodError in Devise::SessionsController#create
undefined method `mypage' for #Devise::SessionsController:0x000000065bcbc8 Did you mean? mypage_url
そこで、コントローラーを作っていないことに気づき、
rails g controller users を実行し、
ルート?を変更しました。
users_controller.rb
ruby
1class UsersController < ApplicationController 2 def index 3 end 4end 5
routes.rb
ruby
1Rails.application.routes.draw do 2 devise_for :users 3 # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html 4 get "users/:id" => "users#index", as: :mypage 5 6end 7
しかし、それでもエラーは出たままです。
どのようにすればユーザーページに遷移できるのでしょうか?
よろしくおねがいします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2018/02/21 13:22
2018/02/22 00:51