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

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

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

Deviseとは、Ruby-on-Railsの認証機能を追加するプラグインです。

Ruby on Rails

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

Q&A

解決済

1回答

766閲覧

Devise導入後、サインアップ・サインイン画面に遷移したい

pi-nattu

総合スコア61

Devise

Deviseとは、Ruby-on-Railsの認証機能を追加するプラグインです。

Ruby on Rails

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

0グッド

0クリップ

投稿2022/09/10 15:08

編集2022/09/10 15:10

前提

Railsでケーキ屋の通販サイトを作っています。
要件に沿って顧客と管理者で機能を分けて作成しています。

実現したいこと

Deviseを使ったログインをしたいが、トップページから顧客のサインイン、サインアップ画面に遷移できないので、できるようにしたいです。

発生している問題・エラーメッセージ

Cloud9ターミナル

1Started GET "/customers/sign_up" for 106.150.140.40 at 2022-09-10 14:34:42 +0000 2Cannot render console from 106.150.140.40! Allowed networks: 127.0.0.0/127.255.255.255, ::1 3 (0.5ms) SELECT sqlite_version(*) 4 (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC 5Processing by Public::RegistrationsController#new as HTML 6 Customer Load (0.2ms) SELECT "customers".* FROM "customers" WHERE "customers"."id" = ? ORDER BY "customers"."id" ASC LIMIT ? [["id", 1], ["LIMIT", 1]] 7Redirected to https://1118ef5aeb7b4c16aa43d249d3edac29.vfs.cloud9.ap-northeast-1.amazonaws.com/ 8Filter chain halted as :require_no_authentication rendered or redirected 9Completed 302 Found in 28ms (ActiveRecord: 0.8ms | Allocations: 11956) 10 11 12 13

該当のソースコード

ruby

1class ApplicationController < ActionController::Base 2 before_action :configure_permitted_parameters, if: :devise_controller? 3 4 protected 5 6 def configure_permitted_parameters 7 devise_parameter_sanitizer.permit(:sign_up, keys: [:email, :password, :last_name, 8 :first_name, :last_name_kana, :first_name_kana, :postal_code, :address, 9 :telephone_number]) 10 end 11end 12

ruby

1<p>未入会の方は新規会員登録お願いいたします</p> 2 3<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %> 4 <%= render "public/shared/error_messages", resource: resource %> 5 6 <div class="field"> 7 <%= f.label :email %>(メールアドレス)<br /> 8 <%= f.email_field :email, autofocus: true, autocomplete: "メールアドレス" %> 9 </div> 10 11 <div class="field"> 12 <%= f.label :last_name %>(姓)<br /> 13 <%= f.text_field :last_name, autofocus: true, autocomplete: "姓" %> 14 </div> 15 16 <div class="field"> 17 <%= f.label :first_name %>(名)<br> 18 <%= f.text_field :first_name, autofocus: true, autocomplete: "名" %> 19 </div> 20 21 <div class="field"> 22 <%= f.label :last_name_kana %>(姓カナ)<br /> 23 <%= f.text_field :last_name_kana, autofocus: true, autocomplete: "姓(カナ)" %> 24 </div> 25 26 <div class="field"> 27 <%= f.label :first_name_kana %>(名カナ)<br /> 28 <%= f.text_field :first_name_kana, autofocus: true, autocomplete: "名(メイ)" %> 29 </div> 30 31 <div class="field"> 32 <%= f.label :postal_code %>(郵便番号)<br /> 33 <%= f.text_field :postal_code, autofocus: true, autocomplete: "郵便番号" %> 34 </div> 35 36 <div class="field"> 37 <%= f.label :address %>(住所)<br /> 38 <%= f.text_field :address, autofocus: true, autocomplete: "住所" %> 39 </div> 40 41 <div class="field"> 42 <%= f.label :telephone_number %>(電話番号)<br /> 43 <%= f.text_field :telephone_number, autofocus: true, autocomplete: "電話番号" %> 44 </div> 45 46 <div class="field"> 47 <%= f.label :password %> 48 <% if @minimum_password_length %> 49 <em>(<%= @minimum_password_length %> characters minimum)</em> 50 <% end %><br /> 51 <%= f.password_field :password, autocomplete: "new-password" %> 52 </div> 53 54 <div class="field"> 55 <%= f.label :password_confirmation %><br /> 56 <%= f.password_field :password_confirmation, autocomplete: "new-password" %> 57 </div> 58 59 <div class="actions"> 60 <%= f.submit "Sign up" %> 61 </div> 62<% end %> 63 64<%= render "public/shared/links" %> 65

ruby

1# frozen_string_literal: true 2 3class AddDeviseToCustomers < ActiveRecord::Migration[6.1] 4 def self.up 5 create_table :customers do |t| 6 ## Database authenticatable 7 t.string :email, null: false, default: "" 8 t.string :encrypted_password, null: false, default: "" 9 10 ## Recoverable 11 t.string :reset_password_token 12 t.datetime :reset_password_sent_at 13 14 ## Rememberable 15 t.datetime :remember_created_at 16 17 ## Trackable 18 # t.integer :sign_in_count, default: 0, null: false 19 # t.datetime :current_sign_in_at 20 # t.datetime :last_sign_in_at 21 # t.string :current_sign_in_ip 22 # t.string :last_sign_in_ip 23 24 ## Confirmable 25 # t.string :confirmation_token 26 # t.datetime :confirmed_at 27 # t.datetime :confirmation_sent_at 28 # t.string :unconfirmed_email # Only if using reconfirmable 29 30 ## Lockable 31 # t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts 32 # t.string :unlock_token # Only if unlock strategy is :email or :both 33 # t.datetime :locked_at 34 35 36 # Uncomment below if timestamps were not included in your original model. 37 t.string :last_name, null: false 38 t.string :first_name, null: false 39 t.string :last_name_kana, null: false 40 t.string :first_name_kana, null: false 41 t.string :postal_code, null: false 42 t.string :address, null: false 43 t.string :telephone_number, null: false 44 t.timestamps null: false 45 end 46 47 add_index :customers, :email, unique: true 48 add_index :customers, :reset_password_token, unique: true 49 # add_index :customers, :confirmation_token, unique: true 50 # add_index :customers, :unlock_token, unique: true 51 end 52 53 def self.down 54 # By default, we don't want to make any assumption about how to roll back a migration when your 55 # model already existed. Please edit below which fields you would like to remove in this migration. 56 raise ActiveRecord::IrreversibleMigration 57 end 58end 59

ruby

1<h2>Log in</h2> 2 3<%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %> 4 <div class="field"> 5 <%= f.label :email %><br /> 6 <%= f.email_field :email, autofocus: true, autocomplete: "email" %> 7 </div> 8 9 <div class="field"> 10 <%= f.label :password %><br /> 11 <%= f.password_field :password, autocomplete: "current-password" %> 12 </div> 13 14 <% if devise_mapping.rememberable? %> 15 <div class="field"> 16 <%= f.check_box :remember_me %> 17 <%= f.label :remember_me %> 18 </div> 19 <% end %> 20 21 <div class="actions"> 22 <%= f.submit "Log in" %> 23 </div> 24<% end %> 25 26<%= render "public/shared/links" %> 27

customersのテーブル定義書▼
customersのテーブル定義書

試したこと

  • application_controllersとdevise.rbにcustomerのサインアップに必要なカラムを追加

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

ruby:3.1.2

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

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

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

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

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

guest

回答1

0

自己解決

一度アプリケーションを消してもう一度作り直し、落ち着いてマイグレーションファイルのカラムの設定や、Viewページを作成したら表示されました。
おそらく編集しているうちに余計なものまで消してしまっていたのかもしれません。

投稿2022/09/11 14:02

pi-nattu

総合スコア61

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問