Devise current_user weird behavior after upgrade to ruby 1.9.3

自古美人都是妖i 提交于 2019-12-13 03:41:40

问题


I have upgraded by project from ree-1.8.7 to 1.9.2p429.

I have an attribute in my devise model named silhouette_user_id. In views and occasionally in my ruby code, calling

current_user.silhouette_user_id

returns a different (and WRONG) value than

current_user[:silhouette_user_id]

which returns the right value.

Though I could search and replace to fix this, I'm worried that other attributes will behave the same way. This is a LARGE project and I really need to determine why this is happening.

Any ideas would be greatly appreciated.


回答1:


I solved this issue. During the upgrade I had tried to update how I was defining new methods for the User class. Unfortunately, I did it wrong. I used

  def define_new_method(key, value)
    self.class.send(:define_method, key.to_sym) do
       value
    end
  end

which actually changed the methods for the CLASS User rather than the instance for which it was intended. Changing to this:

  def define_new_method(key, value)
    define_singleton_method key.to_sym, lambda { value }
  end

resulted in the new methods being defined only for the instance intended and not for the current_user instance.



来源:https://stackoverflow.com/questions/17941607/devise-current-user-weird-behavior-after-upgrade-to-ruby-1-9-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!