我想在我的‘团队’的模式来写的方法,但CURRENT_USER正显示出此错误未定义的局部变量或方法`CURRENT_USER“使用设计和轨道3.2
未定义的局部变量或方法`CURRENT_USER”为#
def set_default_url
if current_user.id == self.user_id
"/assets/default_black_:style_logo.jpg"
else
"/assets/default_:style_logo.jpg"
end
end
方法current_user对其他模型和控制器工作正常。我正在像这样调用这个方法。
has_attached_file :logo, :styles => {
:medium => "200x200#",
:thumb => "100x100#",
:small => "50x50#"
},
:default_url => :set_default_url
我使用rails 3.2,ruby 1.9.3和devise 3.1。这似乎很简单,但我不明白错在哪里。如果有人帮我在这里,我会非常感激。
你可能想看看这个http://stackoverflow.com/questions/1568218/access-to-current-user-from-within-a-model-in-ruby-on -rails – Santhosh 2015-03-02 07:29:04
您是否已将'User'模型与'Team'模型关联? – 2015-03-02 07:30:52
@GaganGami是的!当然 – techdreams 2015-03-02 07:33:52