一切正常,直到昨天,今天我打开了应用程序,它上面提到了上述错误。
以下是显示错误的部分
app/views/devise/registrations/_errors.html.slim where line #5 raised:
undefined method `each' for "Signed in successfully.":String
Extracted source (around line #5):
- if flash[:error]
h4 Error messages
ul
- flash[:error].each do |error|
li= error
- if flash[:error_validate_card]
= flash[:error_validate_card]
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
before_filter :save_controller
after_filter :store_location
rescue_from CanCan::AccessDenied do |exception|
flash[:error] = "Access denied."
redirect_to root_path
end
class Devise::SessionsController < DeviseController
# POST /resource/sign_in
def create
if valid_email?(params[:user][:email] , params[:user][:password]) || params[:user][:password].blank?
flash[:error] = "Email or password is incorrect"
redirect_to :back
else
self.resource = warden.authenticate!(auth_options)
set_flash_message(:error, :signed_in) if is_flashing_format?
sign_in(resource_name, resource)
respond_with resource, :location => after_sign_in_path_for(resource)
end
end
观看次数 - &gt;设计 - &gt;注册 - &gt;文件
<%= form_for(CreativeRequestUser.new,:url=>app_creative_requests_path(),:html=>{:method=>:post,:id=>"creative_request_form"}) do|f| %>
此外,我最近从我的应用程序中删除了rails_admin,但即使在此之后它也能正常工作。
非常感谢有关此问题的任何帮助,提前感谢:)
答案 0 :(得分:0)
您正试图通过flash [:error]中的错误进行迭代,但您已将字符串分配给flash[:error]
。
您通常使用flash[:error] = @item.errors.full_messages
来获取消息数组,但在您的情况下,您需要编写代码来修补代码
rescue_from CanCan::AccessDenied do |exception|
flash[:error] << "Access denied." # see I add you message into flash[:error] array
redirect_to root_path
end
与Session控制器相同的人员
flash[:error] << "Email or password is incorrect"
答案 1 :(得分:0)
请更新会话控制器,如
# POST /resource/sign_in
def create
if valid_email?(params[:user][:email] , params[:user][:password]) || params[:user][:password].blank?
flash[:error] = "Email or password is incorrect"
redirect_to :back
else
self.resource = warden.authenticate!(auth_options)
set_flash_message(:notice, :signed_in) if is_navigational_format?
sign_in(resource_name, resource)
respond_with resource, :location => after_sign_in_path_for(resource)
end
end
分配错误:错误而不是:通知 如果is_flashing_format,行set_flash_message(:notice,:signed_in)中的错误?
答案 2 :(得分:0)
最终我发现错误是由于我已经解雇的捆绑更新命令,不得不重新安装所有宝石的旧版本。
自我和所有未来用户的注意事项 - 非常谨慎地使用捆绑包更新。