minoppp411
@minoppp411 (林 みのり)

Are you sure you want to delete the question?

Leaving a resolved question undeleted may help others!

【rails】deviseで新規登録できない

解決したいこと

Ruby on railsでwebアプリを作っています。
deviseを導入し、新規登録画面のビューをカスタム後新規登録ができなくなりました。
解決方法を教えてください。

発生している問題・エラー

名前やメールアドレス、パスワードを入力しても画面遷移しません。

関連するコード

application_controller
class ApplicationController < ActionController::Base
    before_action :configure_permitted_parameters, if: :devise_controller?

  # このアクションを追加
  def after_sign_in_path_for(resource)
    "/user/#{current_user.id}"
  end

  protected

  # 入力フォームからアカウント名情報をDBに保存するために追加
  def configure_permitted_parameters
    devise_parameter_sanitizer.permit(:sign_up, keys: [:name])
  end

end
registarations_controller

# frozen_string_literal: true

class Users::RegistrationsController < Devise::RegistrationsController
  # before_action :configure_sign_up_params, only: [:create]
  # before_action :configure_account_update_params, only: [:update]

  # GET /resource/sign_up
def new
  @user = User.new
end
  # プロフィール画面用のアクションを追加
def detail
  @user = User.find_by(id: params[:id])
end

# protected

# ここのコメントアウトを外してリダイレクト先を指定
# ルートパス名でも良い
# The path used after sign up.
def after_sign_up_path_for(resource)
  "/user/#{current_user.id}"
end
  # POST /resource
  # def create
  #   super
  # end

  # GET /resource/edit
  # def edit
  #   super
  # end

  # PUT /resource
  # def update
  #   super
  # end

  # DELETE /resource
  # def destroy
  #   super
  # end

  # GET /resource/cancel
  # Forces the session data which is usually expired after sign
  # in to be expired now. This is useful if the user wants to
  # cancel oauth signing in/up in the middle of the process,
  # removing all OAuth session data.
  # def cancel
  #   super
  # end

  # protected

  # If you have extra params to permit, append them to the sanitizer.
  # def configure_sign_up_params
  #   devise_parameter_sanitizer.permit(:sign_up, keys: [:attribute])
  # end

  # If you have extra params to permit, append them to the sanitizer.
  # def configure_account_update_params
  #   devise_parameter_sanitizer.permit(:account_update, keys: [:attribute])
  # end

  # The path used after sign up.
  # def after_sign_up_path_for(resource)
  #   super(resource)
  # end

  # The path used after sign up for inactive accounts.
  # def after_inactive_sign_up_path_for(resource)
  #   super(resource)
  # end
end
registrations/new.html.erb
<% provide(:title, "SIGN UP") %>
<main id="app"data-action="users/sign_up">
        <div id="vapp">
            <div class="loginpanel_wrap p-t6 p-b6">
                <div class="loginpanel">
                    <form id="register" method="POST" action="" accept-charset="UTF-8">
                        <input type="hidden" name="_token" value="">
                        <%= form_for(resource, as: resource_name, url: user_registration_path(resource_name)) do |f| %>
                          <%= render "users/shared/error_messages", resource: resource %>
                        <div class="login_title">
                            <h1>新規会員登録</h1>
                            <p class="login_lead">メールアドレスで登録</p>
                        </div>
                        <div class="form_item">
                            <div class="input_head">
                          <p><%= f.label :メールアドレス %></p>
                            </div>
                            <div class="input_body">
                          <%= f.email_field :email, autofocus: true, autocomplete: "email" %>
                            </div>
                        </div>
                        <div class="form_item">
                            <div class="input_head">
                                <p><%= f.label :ユーザー名 %> <em>(8文字まで)</em></p>
                            </div>
                            <div class="input_body">
                              <%= f.text_field :name, :placeholeder => "ユーザー名", autofocus: true, maxlength: "8" %>
                            </div>
                        </div>
                        <div class="form_item">
                            <div class="input_head">
                                <p><%= f.label :パスワード(英数字8文字以上)%></p>
                            </div>
                            <div class="input_body">
                            <% if @minimum_password_length %>
                            <em>(<%= @minimum_password_length %> characters minimum)</em>
                            <% end %><br />
                            <%= f.password_field :password, autocomplete: "new-password" %>                               
                            <i class="fa icon_eye fa-eye">
                            </i>
                            </div>
                        </div>
                        <div class="form_item">
                            <div class="input_head">
                                <p><%= f.label :確認用パスワード %></p>
                            </div>
                            <div class="input_body">
                            <%= f.password_field :password_confirmation, autocomplete: "new-password" %>
                            <i class="fa icon_eye fa-eye">
                                </i>
                            </div>
                        </div>
                        <div class="checkbox_area flexbox">
                            <p class="checkbox_content mt-4">
                                <span class="checkbox_wrapper">
                                    <label>
                                        <input id="is_guideline" type="checkbox" name="is_kiyaku">
                                        <span>
                                            <a href="#" target="_blank">利用規約</a>
                                            と
                                            <a href="#" target="_blank">個人情報保護法</a>
                                            に同意します。
                                        </span>
                                    </label>
                                </span>
                            </p>
                        </div>
                        <div class="submit_buttons">
                        <%= f.submit "無料で会員登録する",class:"waves-effect waves-light btn-large registration-btn" %>
                        </div>
                        <div class="m-t3">
                        <%= render "users/shared/links" %>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </main>  
<% end %>
routes.rb
Rails.application.routes.draw do

  devise_scope :users do
    get '/users', to: redirect("/users/sign_up")
  end

  devise_for :users, :controllers => {
  :registrations => 'users/registrations',
  :sessions => 'users/sessions'   
} 

devise_scope :user do
  get "user/:id", :to => "users/registrations#detail"
  get "signup", :to => "users/registrations#new"
  get "login", :to => "users/sessions#new"
  get "logout", :to => "users/sessions#destroy"
end
  get "users/index", to: "users#index"

  root :to => "home#index"

  get "sample", to: "sample#index"
  resources :users
  # For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
end

念の為githubのソースコードを載せます。
URL【 https://github.com/Minori411/minoirofake

自分で試したこと

・registrarions_controllerにnewメソッドを追加した。

初心者なのでわからないことばかりですがどうかよろしくお願いいたします。

0

1Answer

registrations/new.html.erb

<form id="register" method="POST" action="" accept-charset="UTF-8">

のactionに何も入っていない。

0Like

Comments

  1. @minoppp411

    Questioner

    ありがとうございます

Your answer might help someone💌