使用aldeed:autoform我被拒绝访问

时间:2016-11-06 20:15:01

标签: meteor meteor-autoform

我试图在meteor validatedmethod简单架构和集合2中使用autoform。但是,当我在文本字段中输入值时,我得到:

undefined error:403
errorType:"Meteor.Error"
message:"Access denied [403]"
reason:"Access denied"
stack:"Error↵    at Connection._livedata_result http://localhost:3000/packages/ddp-client.js`

我的代码使用以下模板:

{{#autoForm collection=club id="insertClubs" type="insert"}}
<fieldset>
  <legend>Add a Club</legend>
  {{> afQuickField name='name'}}
  {{> afQuickField name='number'}}
  {{> afQuickField name='updated'}}
  {{> afQuickField name='created'}}
</fieldset>
<button type="submit" class="btn btn-primary">Insert</button>
{{/autoForm}}

然后我使用事件助手来听取提交并调用一个经过验证的方法:

submit .btn btn-primary'(event, instance) {
  console.log('test');

  insert.call( {
    name: 'test',
    number: 3,
    updated: new Date(),
    created: new Date()
  }, (err, res) => {
    console.log(err);
  });
}

这是插入调用本身:

export const insert = new ValidatedMethod({
name: 'Clubs.methods.insert',
validate: Clubs.simpleSchema().validator(),
run(newClub) {
  // In here, we can be sure that the newClub argument is
  // validated.
 console.log('insert new club');
if (!this.userId) {
  throw new Meteor.Error('Clubs.methods.insert.not-logged-in',
    'Must be logged in to create a club.');
}

Clubs.insert(newClub)
}
});

我认为这个设置实际上并没有调用我的插入方法,因为我没有看到console.log,但流星回来时出现错误。知道可能是什么问题吗?

1 个答案:

答案 0 :(得分:0)

搜索并尝试后,我遇到了属性meteormethod和type属性。配置这似乎调用我的mdg验证方法,并照顾授权,所以它似乎。请参阅以下内容,了解如何使用此功能:

  {{#autoForm collection=club id="insertClubs" type="method" meteormethod="Clubs.methods.insert"}}
  <fieldset>
    <legend>Add a Club</legend>
    {{> afQuickField name='name'}}
    {{> afQuickField name='number'}}
    {{> afQuickField name='updated'}}
    {{> afQuickField name='created'}}
  </fieldset>
  <button type="submit" class="btn btn-primary">Insert</button>
  {{/autoForm}}  

有关其他详细信息,请参阅:https://github.com/aldeed/meteor-autoform#non-collection-forms