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

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

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

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

AWS(Amazon Web Services)

Amazon Web Services (AWS)は、仮想空間を機軸とした、クラスター状のコンピュータ・ネットワーク・データベース・ストーレッジ・サポートツールをAWSというインフラから提供する商用サービスです。

Q&A

解決済

2回答

1747閲覧

新規登録画面、ログイン画面への遷移時に毎回railsの初期画面が出てくることに関して

kaho20181118

総合スコア2

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

AWS(Amazon Web Services)

Amazon Web Services (AWS)は、仮想空間を機軸とした、クラスター状のコンピュータ・ネットワーク・データベース・ストーレッジ・サポートツールをAWSというインフラから提供する商用サービスです。

0グッド

0クリップ

投稿2021/06/27 06:21

ruby on rails ```### 前提・実現したいこと 新規登録画面、ログイン画面への遷移を成功させたい。 railsの初期画面が出てくる原因を知りたい。 今スクールの事前課題中でRuby on railsで本の感想投稿システムを作っています。 新規登録機能、ログイン機能を実装中に以下のエラーが発生しました。 ### 発生している問題・エラーメッセージ

新規登録画面、ログイン画面を見る際、エラーメッセージは出ていなのにブラウザにはYay! You’re on Rails!のrailsの初期画面が毎回出てくる。

### 該当のソースコード devise/session/new.html.erb ```ここに言語を入力 <h2>Log in</h2> <%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %> <div class="field"> <%= f.label :name %><br /> <%= f.text_field :name, autofocus: true, autocomplete: "name" %> </div> <div class="field"> <%= f.label :password %><br /> <%= f.password_field :password, autocomplete: "current-password" %> </div> <% if devise_mapping.rememberable? %> <div class="field"> <%= f.check_box :remember_me %> <%= f.label :remember_me %> </div> <% end %> <div class="actions"> <%= f.submit "Log in" %> </div> <% end %> <%= render "devise/shared/links" %>

/bookers2/app/controllers/application_controller.rb

class ApplicationController < ActionController::Base before_action :configure_permitted_parameters, if: :devise_controller? protected def configure_permitted_parameters devise_parameter_sanitizer.permit(:sign_up,keys:[:email]) end end

devise/registrations/new.html.erb

h2>Sign up</h2> <%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %> <%= render "devise/shared/error_messages", resource: resource %> <div class="field"> <%= f.label :name %><br /> <%= f.text_field :name, autofocus: true, autocomplete: "name" %> </div> <div class="field"> <%= f.label :email %><br /> <%= f.email_field :email, autofocus: true, autocomplete: "email" %> </div> <div class="field"> <%= f.label :password %> <% if @minimum_password_length %> <em>(<%= @minimum_password_length %> characters minimum)</em> <% end %><br /> <%= f.password_field :password, autocomplete: "new-password" %> </div> <div class="field"> <%= f.label :password_confirmation %><br /> <%= f.password_field :password_confirmation, autocomplete: "new-password" %> </div> <div class="actions"> <%= f.submit "Sign up" %> </div> <% end %> <%= render "devise/shared/links" %>

/bookers2/app/models/user.rb

class User < ApplicationRecord # Include default devise modules. Others available are: # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable devise :database_authenticatable, :registerable, :recoverable, :rememberable, :validatable end

/bookers2/db/migrate/20210627014202_devise_create_users.rb

# frozen_string_literal: true class DeviseCreateUsers < ActiveRecord::Migration[5.2] def change create_table :users do |t| ## Database authenticatable t.string :email, null: false, default: "" t.string :encrypted_password, null: false, default: "" ## Recoverable t.string :reset_password_token t.datetime :reset_password_sent_at ## Rememberable t.datetime :remember_created_at ## Trackable # t.integer :sign_in_count, default: 0, null: false # t.datetime :current_sign_in_at # t.datetime :last_sign_in_at # t.string :current_sign_in_ip # t.string :last_sign_in_ip ## Confirmable # t.string :confirmation_token # t.datetime :confirmed_at # t.datetime :confirmation_sent_at # t.string :unconfirmed_email # Only if using reconfirmable ## Lockable # t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts # t.string :unlock_token # Only if unlock strategy is :email or :both # t.datetime :locked_at t.string :name t.timestamps null: false end add_index :users, :email, unique: true add_index :users, :reset_password_token, unique: true # add_index :users, :confirmation_token, unique: true # add_index :users, :unlock_token, unique: true end end

routes.rb

Rails.application.routes.draw do devise_for :users # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html end

試したこと

routingの確認→ devise_for :usersのみしか記載されておらずいじった形跡なし

補足情報(FW/ツールのバージョンなど)

Gemfileの最後にgem 'devise'を追加。
routes.rbに devise_for :usersが自動的に追加。
devise.rbでコメントアウトを外し、カッコの中のemail→nameにして、config.authentication_keys = [:name]と記載。
views/devise/sessions/new.html.erbにnameのフォームを追加し、emailのフォームの記載部分を削除。views/devise/registrations/new.html.erbにnameのフォームを追加。
_devise_create_users.rbにt.timestamps null: falseの真上に t.string :nameを追加。

上記の作業を行いました。
今回が初めての質問で至らぬ点も多いと思いますが、回答よろしくお願いいたします。

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

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

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

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

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

guest

回答2

0

自己解決

理由はわかりませんでしたが、解決しました。おそらくviewページをいじったのが原因っぽいです。

投稿2021/07/27 12:17

kaho20181118

総合スコア2

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

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

0

Deviseをinstallしたとき、終了メッセージのなかに routes.rbにrootを定義しろ、ってあったの見落したのでは。
それを定義してみてください

投稿2021/06/27 08:23

winterboum

総合スコア23347

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

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

kaho20181118

2021/06/27 08:43

回答ありがとうございます。 とりあえず適当にトップページをrootで定義してみましたが、次はトップページ以外のページに移動ができなくなりました。 URLを検索しても全てトップページに戻ってきてしまいます( ; ; )
winterboum

2021/06/27 11:39

Deviseが定義したものと、root以外の定義がないから、それ以外には行けないですね
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問