前提・実現したいこと
Ruby on rails の練習で、ユーザーの登録、ログインを簡単に作っています。
form_for を用いてuser_controllerのcheckというメソッドにアクセスしたいのですが、Nameerrorが出てしまい解決方法がわかりません。
発生している問題・エラーメッセージ
NameError in Users#show Showing /Users/user/re-twitter/app/views/users/show.html.erb where line #8 raised: undefined local variable or method `check' for #<#<Class:0x00007f8c8be07dc8>:0x00007f8c8db19b78> Did you mean? check_box
該当のソースコード
ruby
1class UsersController < ApplicationController 2 def index 3 @users = User.all 4 end 5 6 def show 7 8 end 9 10 11 12 def create 13 @user = User.new 14 @user.name = params[:user][:name] 15 @user.email = params[:user][:email] 16 @user.password = params[:user][:password] 17 @user.save 18 redirect_to '/users/show' 19 end 20 21 def check 22 if users.exists?(name: params[:user][:email]) == true && 23 users.exists?(name: params[:user][:password]) == true 24 25 redirect_to '/users/index' 26 else 27 redirect_to '/users/show' 28 end 29 end 30 31end 32
html
1<h2>ログイン</h2> 2 3<p> 4<%= form_for(@user, url: {controller: User , action:check}) do |f| %> 5<%= f.label :name %> 6<%= f.text_field :name %> 7<%= f.label :password %> 8<%= f.text_area :password %> 9<%= f.submit 'ログイン'%> 10<% end %></p> 11
ruby
1Rails.application.routes.draw do 2 get 'tweets/index' 3 get 'tweets/show' 4 get 'tweets/new' 5 get 'users/index' 6 get 'users/show' 7 get 'users/login' 8 post "users" => "users#create" 9 post "users" => "users#check" 10 # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html 11end 12
試したこと
form_forの書き方をググり確認した。
補足情報(FW/ツールのバージョンなど)
鬼初心者でツッコミどころしかないと思いますが、是非容赦無く突っ込んでいただけると嬉しいです。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/07/15 06:48
2019/07/15 07:55