我正在玩这个演示应用程序https://github.com/kagemusha/ember-rails-devise-demo,它使用Ember为Rails创建Devise注册的JavaScript实现。该应用程序使用CoffeeScript。我使用coffeescript.org网站上的编译器将其转换为JavaScript,但现在我收到了这些意外的令牌和字符串错误。我对Ember非常缺乏经验而且不知道如何制作头像或错误消息的尾巴。
例如,在设置文件的顶部,代码执行此memoization检查(coffeescript和JavaScript版本的语法相同)
App.urls ||= {}
加载应用时会触发此错误。
Uncaught SyntaxError: Unexpected token = :3000/assets/settings.js?body=1:1
同样的事情发生在authentications_helper文件中的相同类型的代码
App.Authentication ||= {}
会触发此错误
Uncaught SyntaxError: Unexpected token = authentication_helper.js:1
但是,它显然也会影响authentication_helper文件中的其余代码。当我尝试注册时,我点击模板中的链接
{{view App.MenuItem href="#/registration" label="Register"}}
调用App.RegistrationRoute
中的寄存器功能App.RegistrationRoute = Ember.Route.extend({
model: function() {
Ember.Object.create();
},
actions: {
register: function() {
log.info("Registering...");
App.Authentication.register(this);
},
尝试在authentication_helper文件中触发此注册函数(顶部有App.Authentication ||= {}
的文件),但我得到了
Uncaught TypeError: Cannot call method 'register' of undefined
我猜这个App.Authentication不是defined
,因为与缓存函数中的未知=相关的错误。
我是否已经为您提供了足够的代码来帮助我在这些错误方面取得一些进展?
App.Authentication.register = function(route) {
$.ajax({
url: App.urls.register,
type: "POST",
data: {
"user[name]": route.currentModel.name,
"user[email]": route.currentModel.email,
"user[password]": route.currentModel.password,
"user[password_confirmation]": route.currentModel.password_confirmation
},
success: function(data) {
App.currentUser = data.user;
App.LoginStateManager.transitionTo("authenticated");
route.transitionTo('home');
},
error: function(jqXHR, textStatus, errorThrown) {
route.controllerFor('registration').set("errorMsg", "That email/password combo didn't work. Please try again");
}
});
};
答案 0 :(得分:0)
App.urls ||= {}
无效JS,所以我怀疑你的咖啡脚本没有正确翻译成JS。你是对的,App.Authentication
没有定义,导致你的其他问题。 App.urls ||= {}
的JS翻译为App.urls = App.urls || {}
。