Coffeescript访问current_user [英] Coffeescript access to current_user

查看:67
本文介绍了Coffeescript访问current_user的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个Rails应用程序。

I'm writing a Rails app.

在CoffeeScript中,我想访问current_user及其与员工的关系。

In CoffeeScript, I would like to access the current_user along with it's relationship to an employee.

这是我正在尝试的代码:

This is the code I'm trying:

    $.create "/events/",
      event:
        title: title,
        starts_at: "" + start,
        ends_at: "" + end,
        all_day: allDay,
        hours: hours,
        employee_id: current_user.employee_id
        # pickup the current employee

但是,控制台显示-未捕获的ReferenceError:未定义current_user

But, the console shows - Uncaught ReferenceError: current_user is not defined

感谢您的帮助!

推荐答案

我建议使用gem'gon',它对于在Rails应用程序中将数据从红宝石传递到咖啡非常有用。这是关于gon用法的 The Railscast ,这是 Gon的存储库

I would suggest using the gem 'gon' , which is useful for passing data from ruby to coffee in rails application . Here is the Railscast about gon's usage , and this is the repository of 'Gon'.

这篇关于Coffeescript访问current_user的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆