上図の Login や Registry ボタンを押したあとに遷移先のviewにて notice を表示させたい。
(notice でログインに成功しました や 登録に成功しました と表示させたい)
何が原因なのかわからないため、どこが悪いのかお気づきの方いらっしゃいましたらアドバイスいただけませんでしょうか?
###発生している問題・エラーメッセージ
Login や Registry ボタン押下後の遷移先のview にて notice が表示されない
###該当のソースコード
notice の挙動だけ見たいので、userモデルを利用してのログイン成不判定は行っていません。
ボタン押すだけでログインできるよう(遷移されるよう)になっています。(ざる状態)
コントローラー
class HomeController < ApplicationController def top end def login if params[:login] == "login" redirect_to aiu_path, notice: 'ログインに成功しました。' elsif params[:regi] == "regi" redirect_to regi_path end end def regi end def aiu end end
top.html.erb
遷移元 view
<form class="form-horizontal" action="login" method="POST"> <fieldset> <!-- Text input--> <div class="form-group"> <label class="col-md-4 control-label" for="Login">Login</label> <div class="col-md-4"> <input id="Login" name="Login" type="text" placeholder="" class="form-control input-md"> <span class="help-block">Enter login</span> </div> </div> <!-- Password input--> <div class="form-group"> <label class="col-md-4 control-label" for="passwordinput">Password</label> <div class="col-md-4"> <input id="passwordinput" name="passwordinput" type="password" placeholder="" class="form-control input-md"> <span class="help-block">Enter password</span> </div> </div> <!-- Button (Double) --> <div class="form-group"> <label class="col-md-4 control-label" for="buttonLogin"></label> <div class="col-md-8"> <button id="buttonLogin" name="login" class="btn btn-success" value="login">Login</button> <button id="buttonRegistry" name="regi" class="btn btn-primary" value="regi">Registry</button> </div> </div> </fieldset> </form>
遷移先 view
aiu.html.erb
<%= notice %>
###気になること
遷移元のフォーム部分を form_tag を使わずにそのままhtmlで直打ちしているせいなのか?Login ボタン押下後にエラーが表示されてしまうため application_controller.rbに1行追加しております。(:null_session部分)
class ApplicationController < ActionController::Base # Prevent CSRF attacks by raising an exception. # For APIs, you may want to use :null_session instead. protect_from_forgery with: :exception protect_from_forgery with: :null_session end
###補足情報(言語/FW/ツール等のバージョンなど)
ruby 2.3.0
rails 4.0.0
centos7.2
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。