bloc referral

If you are interested in learning to code with a mentor, try bloc and get $100 off.
Showing posts with label ruby gem. Show all posts
Showing posts with label ruby gem. Show all posts

Monday, August 11, 2014

email validations for arrays in rails

Sometimes things just aren't that easy. Rails is definitely nice when you do everything out of the box and do not veer to far from the path; I am quickly finding that there are some things that are difficult figure out.

For example I had a task late afternoon to validate emails that are stored in an Array. I original stored all emails as strings but due to way the Rails Mailer works and the needs of the application, the emails are now being collected using CSV(separate by commas) in a string. I am easily able to split that string using split(",") and serializing that into an array. I am also handling single emails by converting them using the Rails method Array.wrap(). Those 2 methods could be blog post in their selves but I am opting to just explain my next issue.

The trouble with storing the emails in an Array is that it broke all my email validations, which does not check a string of emails,  I now am tasked with testing the validations by hand, after discovering that the Active Validator only validates strings.


Validate an array of emails.
emails: ["ilikerobot[at]gmail.com, hello[at]briandouglas.me"]

emails.split(",")

emails: ["ilikerobot[at]gmail.com", "hello[at]briandouglas.me"]

With this being my first major case where Rails couldn't do what, I am considering looking at the Active Validator to see if I can contribute to it and add this functionality, but it might be better as a gem. I am sure it would take longer than a night to implement but it could be a cool challenge to create my first gem and this idea seems simple enough.

My first implementation:








My final implementation *after peer review, it turned out I wrote too much code just to check for the validation of an email :)







I also did the same validation in Javascript, on the client-side.




Saturday, February 1, 2014

Used a Gem: instead of struggling to build my own solution


So I spent most of Thursday and Friday Morning trying to create my own tags for my Bookmarks app, but after a long conversation with a Bloc Mentor this morning, I discovered how to use the Ruby toolbox and found the acs_as_taggable_on gem. I was set on getting this done on my own but had to implement my 3 hour rule and ask for help.

It still took me a while to figure out that I had to rake db:drop:all my database in order to implement the new gem properly, I got it to work with less code. I also gain a better understanding on how to properly work with the database. 

If you are interest here is the railscast thought was recommended for me to watch and get this done. 

acs_as_taggable_on gem
   

Monday, December 23, 2013

Learning Ruby The Hardway

As I am now on my second week of Bloc, I have found my self pacing through the first portion rather quickly. In order to supplement my learning I have opted to also go through the Zed Shaw book, Learn Ruby the Hardway. I am very pleased with the different exercises thus far (52 in total).

I am currently only on #13, but like to complete them while watching television as a sort of winding down for the day...if you can call it that. I also like the fact that the comments below each exercise add more value to the book by going even further in depth. If you decide to use this tool check out this guys blog where he also outlines every exercise while he went through the book.

Code Time:

I did not mention prior in any other post but I put in 94 hours of coding practice/training into Ruby/Javascript prior to Bloc. Bloc has a requirement of at least 25 hours per week, which I completed 26.5 (My personal goal was 35, but I might be a little over zealous). I have placed my Bloc coding time on a seperate Google Doc and will share in a future post.

*The 827 hours is a goal I got from Joshua Kemp and his book.