deviseを利用してログイン機能を作成しています。
空欄などでエラーが発生した時や、ログイン・ログアウトに成功した時のフラッシュメッセージを好きな場所に表示させるにはどのようにすれば良いでしょうか?
layouts/application.html.erb <html> <head> <title>BookersLevel2Herokuapp</title> <%= csrf_meta_tags %> <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> </head> <body> <%= render 'layouts/notifications' %> <%= yield %> </body> </html>
layouts/_notifications.html.erb <% flash.each do |key, value| %> <%= content_tag(:div, value, class: "#{key}") %> <% end %>
registrations/new.html.erb <%= render 'shared/header' %> <div class="user-information"> <div class="user-information-item"> <h2 class="header-space">Sign up</h2> ===ここに表示させたい=== <%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %> <%= render "devise/shared/error_messages", resource: resource %> <div class="field user-form"> <%= f.label :Name %><br /> <%= f.text_field :name, autofocus: true, autocomplete: "name" %> </div> <div class="field user-form"> <%= f.label :email %><br /> <%= f.email_field :email, autofocus: true %> </div> <div class="field user-form"> <%= f.label :password %> <% if @minimum_password_length %> <em>(<%= @minimum_password_length %> characters minimum)</em> <% end %><br /> <%= f.password_field :password, autocomplete: "new-password" %> </div> <div class="field user-form"> <%= f.label :password_confirmation %><br /> <%= f.password_field :password_confirmation, autocomplete: "new-password" %> </div> <div class="actions user-form"> <%= f.submit "Sign up", class: "btn btn-success" %> </div> <% end %> <%= render "devise/shared/links" %> </div> </div> <%= render 'shared/footer' %>
<%= render 'layouts/notifications' %>
がどういうものであるかを説明することはできますか?(あなたの理解度がわからないと、あなたにあった回答ができません。)
現在<%= render 'layouts/notifications' %>で各ページにメッセージを表示はできているのですが、ページの最上部ではなく<h2 class="header-space">Sign up</h2>の下に表示したいです。
説明不足で申し訳ございません。
では、<%= render 'layouts/notifications' %>を表示したい所に置けばいいだけでは無いのですか?
記入する場所を間違えていたようです。
無事解決できました。
ベストアンサーにさせて頂きたいので回答をお願い致します。
最終的にどう解決したのかは私にはわかりません。解決した内容を自分で回答して、自己解決してください。
承知しました。
アドバイスして頂きありがとうございました。
回答1件
あなたの回答
tips
プレビュー