Created
July 11, 2016 10:47
-
-
Save yowchun93/226118b266eb93ce189c0f0ad60e84eb to your computer and use it in GitHub Desktop.
This file contains 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
# Rails customer validation | |
#http://blog.arkency.com/2014/04/mastering-rails-validations-contexts/ | |
# giving context to the validation | |
validates_length_of :slug, minimum: 3, on: :user | |
## editing , giving context when saving the record | |
def edit | |
@user = User.find(params[:id]) | |
if @user.save(context: :admin) | |
redirect # ... | |
else | |
render # ... | |
end | |
end | |
#http://blog.arkency.com/2014/05/mastering-rails-validations-objectify/ | |
## idiomatic way to check user input holy shit | |
def time_data_present? | |
[params[:year], params[:month], params[:day]].all?(&:present?) | |
end | |
## https://www.netguru.co/blog/service-objects-in-rails-will-help | |
#http://blog.arkency.com/2013/09/services-what-they-are-and-why-we-need-them/ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment