Last active
December 13, 2015 22:09
-
-
Save tatey/4982450 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%= 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