English 中文(简体)
J Query Autocomplete / Validate, if/else statement with Mouy onrails
原标题:JQuery Autocomplete / Validate if/else statement with ruby on rails

我有很强的时间,可以解决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)

在“成员”职能中,如果用户投入与任何记录不匹配,而不是添加“成员——与具体条目一致”的内容,则将插入邀请成员吗?

或者说,在不必使用酒吧的情况下,检查是否有电子邮件? 我指的是,在铁路上写这部法律是有办法的,这样用户就能够简单地输入电子邮件,如果真的能够证明,它是否确实存在。 现任成员,如果是假的,就会形成新的成员? 你们的帮助将受到高度赞赏。

感谢你的帮助和时间!

最佳回答

您的第一个问题是:<代码> 替换<>。 http://jqueryui.com/demos/autocomplete/#event-select”rel=“nofollow” 他们从汽车清单中选择一个项目:

select
Triggered when an item is selected from the menu...

用户可以在没有<条码>的的情况下进入。 以各种方式呼吁:

  • They type in something that isn t in the auto-complete list.
  • They enter something that is in the auto-complete list but they type the whole thing. Similarly, the could paste a value in that just happens to be in the list.

因此,你可以依靠<条码>电子显示<>/代码”做任何有用的工作。 如果您在<代码><form>中总结意见,你可以将部分内容与提交活动的形式联系起来,然后人们可以打到,以激发事情,而您的提交者可以将输入值与您的<代码>用户(即:autocomplete 阵列)进行比较,看看他们是否选择了已知的价值;你也可以将选定活动与同一功能联系起来。 与此类似:

<form>
    <input>
</form>

并且

$( input ).autocomplete({
    source: users_for_autocomplete,
    select: function(event, ui) {
        choose_value(ui.item.value);
    }
});
$( form ).submit(function() {
    $( input ).blur();
    choose_value($( input ).val());
    return false;
});
function choose_value(v) {
    for(var i = 0; i < users_for_autocomplete.length; ++i)
        if(users_for_autocomplete[i] == v)
            break;
    if(i == users_for_autocomplete.length) {
        // They entered a new one, go to insert_invitation_membership_form().
        insert_invitation_membership_form(v);
    }
    else {
        // They chose an existing one, go to insert_membership_form().
        insert_membership_form(v);
    }
}

总体技术:

问题回答

暂无回答




相关问题
rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

SSL slowness in EC2

We ve deployed our rails app to EC2. In our setup, we have two proxies on small instances behind round-robin DNS. These run nginx load balancers for a dynamically growing and shrinking farm of web ...

Auth-code with A-Za-z0-9 to use in an URL parameter

As part of a web application I need an auth-code to pass as a URL parameter. I am currently using (in Rails) : Digest::SHA1.hexdigest((object_id + rand(255)).to_s) Which provides long strings like : ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

activerecord has_many :through find with one sql call

I have a these 3 models: class User < ActiveRecord::Base has_many :permissions, :dependent => :destroy has_many :roles, :through => :permissions end class Permission < ActiveRecord::...

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...

热门标签