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

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

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

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

Q&A

0回答

333閲覧

Rails devise login後 error となります。

H.T.

総合スコア5

Ruby on Rails 5

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

0グッド

1クリップ

投稿2020/02/06 00:08

前提・実現したいこと

rails学習の為にpost機能のあるweb appを作成しています。
devise gemをインストールしてlogin機能を試したところ
この様なerrorが発生して@userページに遷移されません。
loginの際に使用したuserはconsoleからsaveした物です。
routes post controller ,user controllerは添付してますが
もし他に必要な詳細がありましたら、確認しますので宜しくお願いします。
routing errorになるのでおそらくlogin後の指定が出来ていません
もし可能でしたら@user pageに遷移できる流れも教えて頂けたら凄くありがたいです

イメージ説明

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

エラーメッセージ [Routing Error](No route matches[POST}"/login") ```ここに言語名を入力 Ruby on Rails ### 試したこと userの情報登録 devise view users作成後 get "login", :to => "users/sessions#new" とあったのでview fileないのsession newをlogin fileとして編集しました。 --- schema file --- ActiveRecord::Schema.define(version: 2020_02_05_111342) do create_table "comments", force: :cascade do |t| t.text "content" t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false t.integer "post_id" end create_table "posts", force: :cascade do |t| t.text "content" t.string "title" t.string "user_name" t.integer "user_id" t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false t.string "img" end create_table "users", force: :cascade do |t| t.string "name", default: "", null: false t.string "char_id", default: "", null: false t.string "img" t.string "email", default: "", null: false t.string "password", default: "", null: false t.string "encrypted_password", default: "", null: false t.string "password_confirmation", default: "", null: false t.string "reset_password_token" t.datetime "reset_password_sent_at" t.datetime "remember_created_at" t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false t.index ["email"], name: "index_users_on_email", unique: true t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true end end --- post controller ---- class PostsController < ApplicationController before_action :authenticate_user!, only: [:create] def new @post = Post.new end def create @post = Post.new(post_params) respond_to do |format| if @post.save format.html {redirect_to @post, notice: 'Post was successfully created.'} format.json {render json: @post.errors, status: :unprocessable_entity } end end end def show @post = Post.find_by(params[:id]) @user = User.find_by(id: @post.user_id) @comment = @post.comments end def edit end def update end def index @post = Post.find_by(params[:id]) @posts = Post.all end def destroy end def ensure_correct_user @post = Post.find(params[:id]) if @post.user_id != @current_user.id flash[:notice] = "権限がありません" redirect_to("/posts/index") end end private def post_params params.require(:post).permit(:user_name, :title, :content, :post.user_id, :content, :img) end end --- login partial --- <div class="py-4 bg-info"> <div class="container text-center"> <div class="card mt-3"> <h5 class="card-header info-color white-text text-center py-4"> <strong>Login</strong> </h5> <div class="card-body px-lg-5 pt-0" style="color: #757575;"> <!--------------- Form ------------------> <%= form_for(:session, url: login_path) do |f| %> <!-- Email --> <div class="md-form mt-4"> <%= f.label :email %><br /> <%= f.email_field :email, class: 'form-control', autofocus: true, autocomplete: "email" %> </div> <!----------------- Password --------------- --> <div class="md-form mt-2"> <%= f.label :password %><br /> <%= f.password_field :password, class: 'form-control', 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", class: "btn btn-secondary" %> </div> <% end %> <%= render "users/shared/links" %> </div> </div> 宜しくお願い致します。

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

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

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

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

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

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

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

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

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

ただいまの回答率
85.50%

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

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

質問する

関連した質問