Last active
November 2, 2015 16:30
-
-
Save devkinetic/755737dae3e0d1af5fbc to your computer and use it in GitHub Desktop.
Template missing when two validations fail
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
Template is missing | |
Missing template registrants/index, application/index with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :arb, :jbuilder]}. Searched in: * "/home/ubuntu/workspace/backend-dev-test-devkinetic/app/views" * "/usr/local/rvm/gems/ruby-2.2.2/gems/html5-rails-0.1.0/app/views" * "/usr/local/rvm/gems/ruby-2.2.2/gems/devise-3.4.1/app/views" * "/usr/local/rvm/gems/ruby-2.2.2/bundler/gems/activeadmin-8968efcc51cc/app/views" * "/usr/local/rvm/gems/ruby-2.2.2/gems/kaminari-0.16.3/app/views" | |
Extracted source (around line #46): | |
def find(*args) | |
find_all(*args).first || raise(MissingTemplate.new(self, *args)) | |
end | |
def find_all(path, prefixes = [], *args) | |
Rails.root: /home/ubuntu/workspace/backend-dev-test-devkinetic |
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 HomeController < ApplicationController | |
def index | |
@registrant = Registrant.new # make an instance of Registrant availiable to the form | |
end | |
def thanks | |
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 EmailValidator < ActiveModel::EachValidator | |
def validate_each(record, attribute, value) | |
unless value =~ /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i | |
record.errors[attribute] << (options[:message] || "is not an email") | |
end | |
end | |
end | |
class Registrant < ActiveRecord::Base | |
# We'll need some validations here to make sure the user fills out the form correctly | |
validates :fname, presence: true | |
validates :lname, presence: true | |
validates :cname, presence: true | |
validates :email, presence: true, uniqueness: true, email: true | |
validates :title, presence: true | |
validates :mobile_phone, presence: true, numericality: true, length: { minimum: 10, maximum: 15 } | |
# Make sure they choose at least one of the events to attend | |
validate :one_event_checked | |
def one_event_checked | |
unless welcome_reception || smart_choice_reception | |
errors.add(:selection, "test") | |
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 RegistrantsController < ApplicationController | |
def index | |
@registrant = Registrant.new # fire off the create action | |
render 'home/index' | |
end | |
def create | |
@registrant = Registrant.new(registrant_params) | |
if @registrant.save # did the record pass validadtion? | |
redirect_to thank_you_path | |
else | |
render 'home/index' | |
end | |
end | |
private | |
def registrant_params # only accept values from the form | |
params.require(:registrant).permit(:fname, :lname, :cname, :email, :title, :mobile_phone, :welcome_reception, :smart_choice_reception) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment