[英]Ruby on Rails: no implicit conversion of Array into String (DEVISE)
I recently upgraded to OSX Mavericks 10.9 from 10.7, and since then it has been causing me lots of troubles. 我最近从10.7升级到OSX Mavericks 10.9,此后一直给我带来很多麻烦。 I upgraded Xcode, Command line tools, reinstalled homebrew and rvm, and finally got rails s to work (I spent a good 5 hours getting rmagick to work again).
我升级了Xcode,命令行工具,重新安装了自制软件和rvm,最后使rails正常工作(我花了5个小时使rmagick再次正常工作)。
However, now when I try to access my app from my localhost, I get this error 但是,现在当我尝试从本地主机访问应用程序时,出现此错误
no implicit conversion of Array into String
Here is the rails log: 这是rails日志:
Started GET "/" for 127.0.0.1 at 2014-05-05 02:20:00 -0700
Processing by AccountsController#dashboard as HTML
Completed 500 Internal Server Error in 0.3ms
TypeError (no implicit conversion of Array into String):
app/controllers/application_controller.rb:26:in `check_correct_subdomain'
Rendered /Users/kibaek/.rvm/gems/ruby-2.1.0@onvard/gems/actionpack-3.2.16/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.0ms)
Rendered /Users/kibaek/.rvm/gems/ruby-2.1.0@onvard/gems/actionpack-3.2.16/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (0.8ms)
Rendered /Users/kibaek/.rvm/gems/ruby-2.1.0@onvard/gems/actionpack-3.2.16/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (7.1ms)
This is application_controller.rb where the error is getting called: 这是application_controller.rb,在其中调用错误:
def check_correct_subdomain
if current_user
redirect_to root_url(subdomain: current_user.account.domain) if request.subdomain != current_user.account.domain
end
end
Here are my versions: 这是我的版本:
Kibaeks-MacBook-Pro:onvard_saas kibaek$ ruby -v
ruby 2.1.0p0 (2013-12-25 revision 44422) [x86_64-darwin12.0]
Kibaeks-MacBook-Pro:onvard_saas kibaek$ rails -v
Rails 3.2.16
Kibaeks-MacBook-Pro:onvard_saas kibaek$ bundle -v
Bundler version 1.5.1
Kibaeks-MacBook-Pro:onvard_saas kibaek$ rvm -v
rvm 1.25.25 (stable) by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [https://rvm.io/]
I pushed this to the staging server, and my other developer says it is working locally on his machine, so I think it may have been something I did in the process of upgrading to Mavericks or copy+pasting a bunch of stuff while trying to fix the imagemagick/rmagick error.. 我将其推送到登台服务器上,而我的其他开发人员说它正在本地计算机上运行,因此我认为这可能是我在升级至Mavericks或在尝试修复时复制粘贴某些内容的过程中所做的事情。 imagemagick / rmagick错误..
*I'm able to access my other rails projects, just get this no implicit conversion error on this particular app all of a sudden. *我能够访问我的其他Rails项目,只需在此特定应用上突然获得此无隐式转换错误即可。
Is there any particular reason that I would be getting this error on my local machine, when the other developers don't get it? 当其他开发人员没有收到此错误时,是否有任何特殊原因会导致我在本地计算机上收到此错误? (I'm thinking it's my local settings that are causing the issue, not the code)
(我认为是导致问题的原因是我的本地设置,而不是代码)
Edit: This turned out to be a devise issue with sessions. 编辑:事实证明这是会话的设计问题。 I was able to solve it through Devise upgrade from 1.1.5 to 1.4.5 causes Wrong Number of Arguments error
我能够通过将Devise从1.1.5升级到1.4.5来解决该问题, 导致参数数目错误
Thank you guys for the answers! 谢谢你们的回答! So it seems like it was a problem with the sessions that was causing the error..
因此,似乎是导致该错误的会话存在问题。
I was able to solve this by following Devise upgrade from 1.1.5 to 1.4.5 causes Wrong Number of Arguments error 我能够通过将Devise从1.1.5升级到1.4.5导致错误的Arguments Number错误来解决此问题
I ran rake tmp:clear
and changed the name of the key in the session_store.rb file. 我运行了
rake tmp:clear
并更改了session_store.rb文件中密钥的名称。
Wow I spent 14 hours trying to solve this issue and it turns out there was such an easy solution.. 哇,我花了14个小时来解决这个问题,结果发现有这么简单的解决方案。
It appears that both of the following in your code are evaluating arrays: 看来您的代码中的以下两项都在评估数组:
if current_user
if affiliate
Calling if on an array will give you this error. 在数组上调用if会出现此错误。
I am unsure why you would have current_user as an array unless you are setting it somewhere else in your code, check anywhere you have current_user = 我不确定为什么将current_user作为数组,除非您在代码中的其他地方设置它,请检查您是否有current_user =
For affiliate, find_by_token is returning an array, perhaps try one of the following: 对于会员,find_by_token返回一个数组,也许尝试以下方法之一:
if affiliate.present?
if !affiliate.nil?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.