前提・実現したいこと
ruby no rails でユーザー登録、ログインの簡単なものを作って勉強をしています
ログインをしたつもりがuserが増えている
該当のソースコード
show.html.erb
html
1<% @user = User.new unless @user %> 2<h1>twitter</h1> 3<p>あなたの毎日をつぶやこう</p> 4 5 6<h2>ログイン</h2> 7 8<p> 9<%= form_for(@user,{controller: User , action: :check}) do |f| %> 10<%= f.label :name %> 11<%= f.text_field :name %> 12<%= f.label :password %> 13<%= f.text_area :password %> 14<%= f.submit 'ログイン'%> 15<% end %></p> 16 17<h2>アカウント作成</h2> 18<p> 19 <%= form_for User.new do |f| %> 20 <%= f.label :name %> 21 <%= f.text_field :name %> 22 <%= f.label :email %> 23 <%= f.text_field :email %> 24 <%= f.label :password %> 25 <%= f.text_area :password %> 26 <%= f.submit '登録' %> 27<% end %></p> 28
users_controller.rb
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 31 32end 33
routes.rb
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 post "users" => "users#create" 8 post "users" => "users#check" 9 # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html 10end 11
試したこと
エラーメッセージをコピペして検索してみた
補足情報(FW/ツールのバージョンなど)
超初心者です!バチバチ叩いて教えてくれたら幸いです
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。