作者:爱音乐的李雪梅 | 来源:互联网 | 2023-09-23 19:25
Oksoihavethishelper我有这个助手defcurrent_company_title(Company.find_by_id(params[company_id]
Ok so i have this helper
我有这个助手
def current_company_title
(Company.find_by_id(params["company_id"]).name rescue nil) || (@companies.first.name rescue nil) current_user.company.name
end
Basically what I am achieving with this is the following ...
基本上,我所取得的成果是……
If the param["company_id"] exists then try to get the company and if not then if @companies exists grab the first company name and if not then get the current users company name
如果param["company_id"]存在,则尝试获取公司,如果没有,则获取第一个公司名称,如果没有,则获取当前用户的公司名称
This works but the rescues seem like a hack...any idea on another way to achieve this
这是可行的,但救援看起来像黑客。有没有别的办法
6 个解决方案