title: ruby on rails custom function validate and post
body: <p>I have create a <code>controller</code> named <code>Invites</code> and a <code>model</code> named <code>invite</code> and i have created a new function in the controller named request_invite which i want to use for users to enter their email address, validate it and that it does not exist in the invites table and then post it to the database</p>
  
  <p>invites_controller.rb</p>
  
  <pre><code>class InvitesController &lt; ApplicationController
  
      def request_invite
          render_404 unless request.xhr?
  
          @email = params[:get_invited_email]
  
          if @email
              flash[:notice] = "msg + insert"
          else
              flash[:notice] = "msg"
          end
  
      end
  
  end
  </code></pre>
  
  <p>invite.rb</p>
  
  <pre><code>class Invite &lt; ActiveRecord::Base
  
  end
  </code></pre>
  
  <p>i have not added resources in the routes file</p>
  
  <p>form</p>
  
  <pre><code>&lt;%= form_tag(invite_request_path, :method =&gt; "post", :id =&gt; "landing_request_invite_form") do %&gt;
      &lt;%= text_field_tag 'get_invited_email', nil, :placeholder =&gt; 'Enter your email address' %&gt;
      &lt;%= submit_tag 'Get Invited', :id =&gt; "get_invited_btn" %&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>javascript</p>
  
  <pre><code>  $("#landing_request_invite_form").submit(function(e){
      e.preventDefault();
      var form = $(this);
      var url = form.attr("action");
      var formData = form.serialize(); 
      $.post(url, formData, function(html) { 
          console.log('request done');
      });
      return false;
    });
  </code></pre>
  
  <p>how can i check that the email does not exist? do i use the .find() method?</p>