gpt4 book ai didi

ruby-on-rails - 意外的 keyword_end,期望输入结束

转载 作者:数据小太阳 更新时间:2023-10-29 08:20:26 25 4
gpt4 key购买 nike

我得到一个错误:语法错误,意外的 keyword_end,期待输入结束。通常我不会问这样的问题,但我根本不会出错!这是我的完整模型代码:

错误出现在方法add_gelesen line 48: end 感谢社区!

class Message < ActiveRecord::Base
attr_accessor :current_user, :current_department
before_save :set_sender, :add_gelesen

def set_sender
self.sender_username = @current_user.username
self.sender_model = @current_user.class.to_s
self.sender_id = @current_user.id
if (recipient_username != @current_department.username) && (recipient_model == 'Department')
self.privat = 0
if Object.const_get(recipient_model).find(recipient_id).has_kontakt?(@current_department.id) == false
Object.const_get(recipient_model).find(recipient_id).kontakt(@current_department.id)
end
end
end

def add_gelesen
if self.privat == true

if recipient_username == @current_department.username
f = JSON.parse(@current_department.gelesen)
@current_department.employees.each.do |c|
w = f["#{c.username}"].nil? ? 0 : f["#{c.username}"]
f["#{c.username}"] = w + 1
end
@current_department.update_column(:gelesen, f.to_json)
else
f = JSON.parse(@current_user.gelesen)
w = f[self.recipient_username].nil? ? 0 : f[self.recipient_username]
f[self.recipient_username] = w + 1
@current_user.update_column(:gelesen, f.to_json)
end

else
u = Object.const_get(self.recipient_model).find(self.recipient_id)
f = JSON.parse(u.gelesen)
@current_department.employees.each.do |c|
w = f["#{c.username}"].nil? ? 0 : f["#{c.username}"]
f["#{c.username}"] = w + 1
end
Department.find(self.recipient_id).employees.each.do |g|
w = f["#{g.username}"].nil? ? 0 : f["#{g.username}"]
f["#{g.username}"] = w + 1
end
u.update_column(:gelesen, f.to_json)
end
end
end

最佳答案

带有 do 的行不应该有 .

@current_department.employees.each.do |c|

应该是

@current_department.employees.each do |c|

do 是开始一个 block 的关键字,而不是 each

上的方法

关于ruby-on-rails - 意外的 keyword_end,期望输入结束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19846219/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com