Skip to content

Instantly share code, notes, and snippets.

@tatey
Last active December 13, 2015 22:09
Show Gist options
  • Save tatey/4982450 to your computer and use it in GitHub Desktop.
Save tatey/4982450 to your computer and use it in GitHub Desktop.
class RetrieverForm
include ActiveModel::Conversion
include ActiveModel::Validations
validate :existance_of_email
def initialize(attributes = {})
@email = attributes[:email]
end
def existance_of_email
unless Invitee.where(email: email}).exists?
errors.add(:email, "doesn't exist")
end
end
end
class Controller
def new
@retriever = RetrieverForm.new(params[:retriever])
end
def create
@retriever = RetrieverForm.new(params[:retriever])
if @retriever.valid?
render :woot
else
render :fuck
end
end
end
<%= retriever.errors.messages if retriever.errors.any? %>
<%= form_for :retriever, url: retriver_path do |f| %>
<%= f.text_field :email %>
<%= f.submit %>
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment