私はいくつかの時間前にStackOverflowの上でこの問題への解決策を見つけました。ここでは、オリジナルのポストhere
を参照してください私
# In application.html.erb
<% flash.each do |name, msg| %>
# New code (allow for flash elements to be arrays)
<% if msg.class == Array %>
<% msg.each do |message| %>
<%= content_tag :div, message, :id => "flash_#{name}" %>
<% end %>
<% else %>
# old code
<%= content_tag :div, msg, :id => "flash_#{name}" %>
<% end %> #don't forget the extra end
<% end %>
と
# Wherever you want Devise's error messages to be handled like
# your other error messages
# (in my case, registrations_controller.rb, a custom controller)
flash[:notice] = flash[:notice].to_a.concat resource.errors.full_messages
のために働いていた...との答えを受け入れることについて考え、50%は少し低いものです! ;)
===== ===== EDIT
にエラーが発生した場合、あなたはコントローラを無効にする必要がありますときに別のページにリダイレクトする必要がある場合(のために考案ウィキや検索のstackoverflowをチェックハウツー)それはそのように見えるはずです
# CUSTOM DEVISE CONTROLLER
class RegistrationsController < Devise::RegistrationsController
# POST /resource
def create
build_resource
if resource.save
if resource.active_for_authentication?
set_flash_message :notice, :signed_up if is_navigational_format?
sign_in(resource_name, resource)
respond_with resource, :location => redirect_location(resource_name, resource)
else
set_flash_message :notice, :inactive_signed_up, :reason => resource.inactive_message.to_s if is_navigational_format?
expire_session_data_after_sign_in!
respond_with resource, :location => after_inactive_sign_up_path_for(resource)
end
else
clean_up_passwords(resource)
# Solution for displaying Devise errors on the homepage found on:
# https://stackoverflow.com/questions/4101641/rails-devise-handling-devise-error-messages
flash[:notice] = flash[:notice].to_a.concat resource.errors.full_messages
redirect_to root_path # HERE IS THE PATH YOU WANT TO CHANGE
end
end
end
私は、ログインをクリックするか、私はSTIL anthoerページにリダイレクトすることだし、そこに私はエラーを取得しています登録するときに...働いていない... – gal
あなたのコントローラーと、変更をオーバーライドする必要が応答経路。私の編集を参照してください。 – Lucas
あなたは私に経路を指定するのを忘れてしまいます::registrations => "registrations" – gal