我有很强的时间,可以解决trick问题。 这里,我试图做到:
I would like to have a text_field
where the user enters the email address of the person they would like to add and Rails validates whether that email address is registered. If that email is registered (and the account exists) it would render from A and send a "join project" email, if the email does not match with one in the db (user does not exist) it would render another form, form B, and send an "invite to SITE" email.
我的职能现在单独运作。 一个是邀请现有用户,另一个是邀请新的用户。 这里是我所拥有的。
观点:
= button_to_function Add Existing User , insert_add_existing_member_form() , :class => "submit"
= button_to_function Add New User , insert_invitation_membership_form() , :class => "floatright submit"
#add_existing_member_form.template.hide
.label_top
= label_tag Enter email address or name
= text_field_tag new_member_email , "", :class => "existing_member_autocomplete"
#membership_form.template.hide
%p Pending acceptance.
= f.fields_for(:memberships, Membership.new(), :child_index => new_membership ) do |ff|
= render membership , :ff => ff
申请:
var insert_add_existing_member_form = function(){
$( #membership_form_footer ).before("<h2>Add Existing User</h2>")
var template = $("#add_existing_member_form").clone()
$("#membership_form_footer").before( template.html() )
$( .existing_member_autocomplete ).autocomplete({
source: users_for_autocomplete,
select: function(event, ui){
insert_membership_form(ui.item)
}
})
}
var insert_membership_form = function(item){
$( #membership_form_footer ).before("<h2>"+item.label+"</h2>")
var template = $( #membership_form ).clone()
$(template).find( #project_memberships_attributes_new_membership_user_id ).val(item.id)
$( #membership_form_footer ).before( template.html().replace(/new_membership/g, new Date().getTime()) )
}
var insert_invitation_membership_form = function(){
$( #membership_form_footer ).before("<h2>Add New User</h2>")
var template = $("#invitation_membership_form").clone()
$("#membership_form_footer").before( template.html().replace(/new_membership/g, new Date().getTime()) )
}
控制器:
@users_for_autocomplete = User.not_member_of(@project.id).to_json(:only => :id, :methods => :label)
在“成员”职能中,如果用户投入与任何记录不匹配,而不是添加“成员——与具体条目一致”的内容,则将插入邀请成员吗?
或者说,在不必使用酒吧的情况下,检查是否有电子邮件? 我指的是,在铁路上写这部法律是有办法的,这样用户就能够简单地输入电子邮件,如果真的能够证明,它是否确实存在。 现任成员,如果是假的,就会形成新的成员? 你们的帮助将受到高度赞赏。
感谢你的帮助和时间!