Open Side Menu Go to the Top
Register
OFFICIAL Ruby on Rails Thread!!! OFFICIAL Ruby on Rails Thread!!!

05-16-2013 , 07:45 AM
Can we talk rails for a minute? What do you guys do with your service logic. I.e. in my current app we have a ton of different emails that are sent on a number of different tasks. Some of the methods (that might mail a certain subset of people) often get called as a model method in the controller. Sometimes we're just calling the mailer (with a delay obviously) in the controller.

I'd love to throw these out into some sort of service layer to remove the clutter from my controllers/models. I'd also like a place where I can throw in more logic with regards to what emails get sent (i.e. we're going to implement a batch email setting, etc).

Since I'm basically 100% self taught, and I know observers are being removed in rails 4... where are people putting these types of calls?
OFFICIAL Ruby on Rails Thread!!! Quote
05-16-2013 , 10:32 PM
Quote:
Originally Posted by Nchabazam
Can we talk rails for a minute? What do you guys do with your service logic. I.e. in my current app we have a ton of different emails that are sent on a number of different tasks. Some of the methods (that might mail a certain subset of people) often get called as a model method in the controller. Sometimes we're just calling the mailer (with a delay obviously) in the controller.

I'd love to throw these out into some sort of service layer to remove the clutter from my controllers/models. I'd also like a place where I can throw in more logic with regards to what emails get sent (i.e. we're going to implement a batch email setting, etc).

Since I'm basically 100% self taught, and I know observers are being removed in rails 4... where are people putting these types of calls?

How are you currently handling mail for a model, are you putting it in the model, or in a mailer?

app/mailers/user_mailer.rb


class UserMailer < ActionMailer::Base
default :from => "ryan@railscasts.com"

def registration_confirmation(user)
@user = user
attachments["rails.png"] = File.read("#{Rails.root}/public/images/rails.png")
mail(:to => "#{user.name} <#{user.email}>", :subject => "Registered")
end
end

http://railscasts.com/episodes/206-a...ler-in-rails-3

Your models shouldn't really have any mail stuff in it, your controllers, may or may not have clutter, but if you make your models fat, your controllers should be skinny. As far as batch jobs, you aren't going to want to stick that in a controller, use a rake task, or some type of job queuing.
OFFICIAL Ruby on Rails Thread!!! Quote
05-17-2013 , 12:44 AM
Quote:
Originally Posted by Mariogs37
lolno

The avg. junior rails dev in NYC is 94k, the avg. for the pilot Dev Bootcamp class was ~83k, not sure what has happened since.

For those who are interested, I started my apprenticeship this week and it's going *relatively* well. Some pro's/con's:

Pro's:
1) Engineer I work with is a complete boss and really great dude
2) Learning PHP/MySQL, stuff I've never seen before
3) We're pushing code that's being used instantly
4) v. good chance of FT offer (from talking to ppl at co)
5) Great hours: get in around 9:30/10, leave anywhere from 5-7.

Con's
1) $3.5k/month
2) PHP/MySQL
Congratulations!

I'm not understanding the "con" of getting paid a semi-living wage to learn on the job. Considering that many people pay 60k+ a lifetime of interest payments for the opportunity to get a free internship in the summer and maybe find a job within a year of graduating, you are already ahead of the curve.

I currently have a similar thing going on. I live in LA and am learning C#, .NET, and SQL Server (plus I have to learn Javascript on my own time to get their site up to the level they want it) and I'm not getting paid as much as you are. I feel incredibly blessed to be in my position though because at the end of the day, there will be something amazing to show off when I'm done. Just use this to learn all you can and shine, make people happy around you, and look to parlay it into something valuable.

I also don't get the con of MySQL. The difference between MySQL and PostgreSQL, at least at the level either you or I would expect to achieve in the near-term, is nominal at best. I'm pretty wicked with SQL, but to get to point where I'd really see a difference between either is a few years off unless you feel like writing the hell that is triggers (don't do that, man).
OFFICIAL Ruby on Rails Thread!!! Quote
05-17-2013 , 01:11 AM
Quote:
Originally Posted by Nchabazam
Can we talk rails for a minute? What do you guys do with your service logic. I.e. in my current app we have a ton of different emails that are sent on a number of different tasks. Some of the methods (that might mail a certain subset of people) often get called as a model method in the controller. Sometimes we're just calling the mailer (with a delay obviously) in the controller.

I'd love to throw these out into some sort of service layer to remove the clutter from my controllers/models. I'd also like a place where I can throw in more logic with regards to what emails get sent (i.e. we're going to implement a batch email setting, etc).

Since I'm basically 100% self taught, and I know observers are being removed in rails 4... where are people putting these types of calls?
I've used a combination of ActionMailers and a background job queue (Resque, DelayedJob, etc.) for this sort of thing. The scheduling of the background job would take place in the controller.

Your models should definitely not have any knowledge of the mailer.
OFFICIAL Ruby on Rails Thread!!! Quote
05-17-2013 , 01:16 AM
Quote:
Originally Posted by Nchabazam
$94k seems awfully high for an actual "junior" dev. What would someone with a few years experience be making? I know NYC has inflated costs of everything, but still.
This, and 3500 * 12 != 94000.

Money shouldn't matter right now anyway. You should be soaking up all the knowledge you can and understand the money will take care of itself later on. My first job a year ago (I'm 100% self-taught) was less than $60k (I'm not in SF or NYC so it's quite fine here) but I got to be around a few other guys that were skilled, humble and good teachers. My stint there has more than paid for itself.
OFFICIAL Ruby on Rails Thread!!! Quote
05-17-2013 , 04:21 AM
Quote:
Originally Posted by AnthonyJoseph
How are you currently handling mail for a model, are you putting it in the model, or in a mailer?

app/mailers/user_mailer.rb


class UserMailer < ActionMailer::Base
default :from => "ryan@railscasts.com"

def registration_confirmation(user)
@user = user
attachments["rails.png"] = File.read("#{Rails.root}/public/images/rails.png")
mail(:to => "#{user.name} <#{user.email}>", :subject => "Registered")
end
end

http://railscasts.com/episodes/206-a...ler-in-rails-3

Your models shouldn't really have any mail stuff in it, your controllers, may or may not have clutter, but if you make your models fat, your controllers should be skinny. As far as batch jobs, you aren't going to want to stick that in a controller, use a rake task, or some type of job queuing.
Well I mean we have a bunch of controller actions that might email up to 200 people. So for example, we might have @object.send_a_bunch_of_emails where @object is some model. I just wanted the loop logic out of the controller for sure. I'm using delayed jobs for now (though I'd like to get onto sidekiq).

http://railscasts.com/episodes/398-service-objects

This seemed to answer some questions. I don't think being able to call @object.send_a_bunch_of_emails is necessarily bad, but it shouldn't be directly in the model. It should be in a module of similar objects that are used by the model, but not related directly to the business logic.

Quote:
Originally Posted by RICHI8
I've used a combination of ActionMailers and a background job queue (Resque, DelayedJob, etc.) for this sort of thing. The scheduling of the background job would take place in the controller.

Your models should definitely not have any knowledge of the mailer.
Man I have some ugly controllers :P
OFFICIAL Ruby on Rails Thread!!! Quote
05-17-2013 , 04:27 AM
And as far as money goes, I might as well share. I'm in Boston (which is really expensive). After less than a year of teaching myself I got offered $40/hour on a contract to hire as the first hire at a 3 person start up. They quickly offered me $61k + 1% equity. Within less than 2 months they bumped the $61k to $75k.

That was a few weeks ago. I honestly never did much due diligence as to what 1% equity could be at various valuations, but I'd imagine it wouldn't be more than a few hundred grand in the 4 years it takes to vest, though more is possible. I just don't know how diluted it would become when they raised additional funds.

I'd guess the real value of the $75k + 1% was around $90k/year. So my starting salary for my first rails job was probably about $76k. I also had more experience in building apps than most people would out of dev bootcamps imo, and in reality am a little less junior than a real junior hire. I don't care a huge amount about a few grand, but I have a huge amount of bargaining power if I really wanted to get bumped up a bit.
OFFICIAL Ruby on Rails Thread!!! Quote
05-17-2013 , 08:50 AM
http://blog.codeclimate.com/blog/201...record-models/

This is a decent read... sort of flies in the face of the railscast I posted before, but I'd imagine it's probably a better set of practices.
OFFICIAL Ruby on Rails Thread!!! Quote
05-17-2013 , 09:23 AM
Quote:
Originally Posted by RICHI8
This, and 3500 * 12 != 94000.

Money shouldn't matter right now anyway. You should be soaking up all the knowledge you can and understand the money will take care of itself later on. My first job a year ago (I'm 100% self-taught) was less than $60k (I'm not in SF or NYC so it's quite fine here) but I got to be around a few other guys that were skilled, humble and good teachers. My stint there has more than paid for itself.
Quote:
Originally Posted by Nchabazam
And as far as money goes, I might as well share. I'm in Boston (which is really expensive). After less than a year of teaching myself I got offered $40/hour on a contract to hire as the first hire at a 3 person start up. They quickly offered me $61k + 1% equity. Within less than 2 months they bumped the $61k to $75k.

That was a few weeks ago. I honestly never did much due diligence as to what 1% equity could be at various valuations, but I'd imagine it wouldn't be more than a few hundred grand in the 4 years it takes to vest, though more is possible. I just don't know how diluted it would become when they raised additional funds.

I'd guess the real value of the $75k + 1% was around $90k/year. So my starting salary for my first rails job was probably about $76k. I also had more experience in building apps than most people would out of dev bootcamps imo, and in reality am a little less junior than a real junior hire. I don't care a huge amount about a few grand, but I have a huge amount of bargaining power if I really wanted to get bumped up a bit.
Could you two possibly go into more detail about how you are self-taught, the path you took to learning and then to a career, your ages if you don't mind, what you were doing before, etc.?
OFFICIAL Ruby on Rails Thread!!! Quote
05-17-2013 , 10:37 AM
Quote:
Originally Posted by Baltimore Jones
Could you two possibly go into more detail about how you are self-taught, the path you took to learning and then to a career, your ages if you don't mind, what you were doing before, etc.?
I'm 29, have been doing a lot of random since graduating, including a lot of poker for a time, and a lot of screwing around. I decided in January of last year to pick up ruby on rails as per a recommendation of a friend (who is a rails developer at a start up). I fumbled around for a while trying to get it to run on windows and other stupid crap, knew no html/css/javascript/ruby, and hadn't looked at any programming in 10 years.

I did have an AP comp sci class in HS and comp sci 102 in college, all in C++. I wasn't totally unfamiliar with stuff, but it was slow going. I worked for a couple months and got familiar with making a very basic app. Then I really didn't do much for a few months. In the summer I started a slightly more ambitious app, which taught me a lot.

I then randomly found out about something called Boston Startup School (now call Startup Institute) in August, which I applied for and got in. It was at the time a free program. So I started coding a little harder since I had some context (i.e. a job seemed attainable since I had no job experience really and no network). Learned a bit of javascript (see: jQuery soup). Got into the program with some basic rails knowledge, basic javascript knowledge at the start of November.

I worked probably 80 hours a week for the 7 weeks the program lasted just coding my ass off. Learned a ton, made use of the smart teachers that came in. Then I went away for Christmas, came home, passed up on two job opportunities that weren't in rails (boo PHP). So that realistically would have been about 6 months worth of actual coding (with the free boot camp in the middle).

I then lost focus for a time, built another (larger) rails app for a friend, built a largish backbone app for a month or so... then my friend emailed me asking if I was still looking for a job at the start of March, and I was just putzing around on my backbone app so I said sure. Came in that afternoon, met the guys at my current job, they offered me a job on the spot, and I've been working there since.

Learned an absolute ton doing it for a living. So I'm realistically about a year worth of coding into web dev from basically no background. I'd say I'm more intermediate than junior, but I'm sure people looking to hire me would disagree

I'm building a somewhat ambitious app in angularjs and rails on the side which I hope to launch to the wild in 6 weeks or so (also for a friend).

I could have expedited the whole process if I had mentors, a better plan for growing my knowledge base, more focus initially, etc... I bet I could have gone from scratch to job in 4 months (of really hard work) if I had had a better roadmap. If you're interested in coding, make use of the community around you. I did it 100% on my own just reading blogs, tutorials, and stackoverflow posts. It sucked. I'm still basically learning that way. It kind of sucks.

I really need to start going to things like angularjs meetups. People are always really helpful (as I am to people who are trying to learn).

tl;dr I programmed my ass off for the past 8 months and have learned a ton, continue to learn a ton, and am getting pretty good at this stuff.

If you have a passion for building things, are reasonably intelligent, and want to give it a shot, you can/will succeed.

Let me know if you have any specific questions about how to go about learning any web dev technologies.
OFFICIAL Ruby on Rails Thread!!! Quote
05-17-2013 , 04:19 PM
Quote:
Originally Posted by RICHI8
This, and 3500 * 12 != 94000.

Money shouldn't matter right now anyway. You should be soaking up all the knowledge you can and understand the money will take care of itself later on. My first job a year ago (I'm 100% self-taught) was less than $60k (I'm not in SF or NYC so it's quite fine here) but I got to be around a few other guys that were skilled, humble and good teachers. My stint there has more than paid for itself.
Right...and I'm not a junior Rails dev in a full-time role...so...comparison isn't fair

I'm doing a 12-week apprenticeship in PHP...
OFFICIAL Ruby on Rails Thread!!! Quote
05-18-2013 , 02:12 PM
Quote:
Originally Posted by Baltimore Jones
Could you two possibly go into more detail about how you are self-taught, the path you took to learning and then to a career, your ages if you don't mind, what you were doing before, etc.?
I'm 25 with no college and August will be the 2 year mark of being in the Web/Software field.

I did various forms of sales for about 5 years and burned out from it and decided I wanted to be on the product side. I went on Google, searched around, read about Web Dev and started with learning HTML, CSS and PHP by reading books and practicing pretty much every night. I was able to combine my previous sales/service skills with some pretty basic HTML/CSS/PHP to land a job at a startup here in San Diego running their Support operation and a blog network of 45+ WordPress blogs.

I noticed that the startup's main product was built using Ruby on Rails and I became interested after all the nice things I'd read and heard about Ruby the language and Rails the framework. Over time my role grew into other more opertions based things like running Ad campaigns and giving our big customers training on our products but I was set on becoming a developer. I started teaching myself Ruby at night. Unfortunately that company didn't have the work/resources to bring along someone as green as me and I left to go to another company in a junior Ruby and PHP role.

From there my learning just kind of took off. I was reading programming books for an hour and half every day (I was able to take public transportation to the office) and programming for about 11 or 12 hours a day (8 hours at work, 3-4 at home). The best choice I ever made was picking Ruby and using it as my single focal point for learning concepts, patterns and general best practices. Focusing on those things has made picking up other languages and really learning libraries and frameworks really easy.

If we were to go off of occupation titles only, which as we all know are quite diluted in this business, I went from a WordPress Developer, to a Programmer to an Engineer in the span of 9 months and nearly tripling my income along the way.

The learning will never stop though and it's embarrassing to think about how much I still suck compared to others.
OFFICIAL Ruby on Rails Thread!!! Quote
05-18-2013 , 03:28 PM
Thank you for the stories Nchabazam and RICHI8. I'm a few years older than both of you but am still encouraged that I can learn on my own if necessary (though certainly a boot camp would be the best option).

For now I have a very basic question. Going through Chris Pine's tutorial, which is excellent:

http://pine.fm/LearnToProgram/?Chapter=07

There is an exercise at the end of that chapter where he wants you to alphabetize an array, without using sort. My code will be messy I'm sure, but it's still helpful to think it through using the basic concepts I know.

So I want to compare the first word to each other word in the array. first = the first word in the array, "words" is the array.

if first >= words.each

What do I have to do to get that part of the code to work? "Comparison of String with Enumerator failed". I've tried various .to_s conversions.
OFFICIAL Ruby on Rails Thread!!! Quote
05-18-2013 , 04:19 PM
You should probably start a new thread asking about self learning stories. I know there are at least 7 posters in this forum who are self taught. Might be interesting to see everyone's opinions and backgrounds.
OFFICIAL Ruby on Rails Thread!!! Quote
05-18-2013 , 04:46 PM
Quote:
Originally Posted by Baltimore Jones
Thank you for the stories Nchabazam and RICHI8. I'm a few years older than both of you but am still encouraged that I can learn on my own if necessary (though certainly a boot camp would be the best option).

For now I have a very basic question. Going through Chris Pine's tutorial, which is excellent:

http://pine.fm/LearnToProgram/?Chapter=07

There is an exercise at the end of that chapter where he wants you to alphabetize an array, without using sort. My code will be messy I'm sure, but it's still helpful to think it through using the basic concepts I know.

So I want to compare the first word to each other word in the array. first = the first word in the array, "words" is the array.

if first >= words.each

What do I have to do to get that part of the code to work? "Comparison of String with Enumerator failed". I've tried various .to_s conversions.
Ruby's error messages are quite good so I'm going to sound redundant here

Feel free to ignore this part for now: The problem is that your comparison is trying to compare a String,which is stored in the 'first' variable, with an Enumerator (Words.each). Sending each to an Enumerable object (Array, Hash, etc.) without a block converts that Enumerable type to an Enumerator object. Ruby (rightfully so) can't do the necessary equality check to compare a String to an Enumerator, they are just too different of objects.

I won't give you the code solution but I will tell you that what you want to do is iterate over that words Array and inside the block do that comparison of first to each word in the words Array.

Kudos to start off with Chris Pine's book. It's the book I started Ruby with and recommend to everyone else. It's an easy read and the problems are actually quite hard. Stick to it!
OFFICIAL Ruby on Rails Thread!!! Quote
05-19-2013 , 03:50 AM
Okay, so what I think I want to do is find the lowest value in the array and then pop that out into the beginning of a new array (alphabetized), repeat until the old array is empty. Is there anything wrong with this logic? And is there anything wrong with this:

Quote:
alphabetical.push(x)
words.delete(x)
alphabetical is the new empty array, words is the original array. x is a variable that equals whichever member of the words array is currently being checked.
OFFICIAL Ruby on Rails Thread!!! Quote
05-19-2013 , 01:03 PM
Got it finally, thanks RICH. So messy, but here it is:

Quote:
words = []
puts "Type words, press just enter when done!"

word = gets.chomp

while word != ''
words.push word
word = gets.chomp
end

puts "In alphabetical order (not including caps!):"
puts

alphabetical = []
n = words.length-1

while words.length != 0
word = words[n]
x = 0
words.each do |the|
if the >= word.to_s
x += 1
end
end
if x == words.length
words.delete(word)
alphabetical.push(word)
n = words.length-1
else n-=1
end
end


puts alphabetical
OFFICIAL Ruby on Rails Thread!!! Quote
05-19-2013 , 01:25 PM
Quote:
Originally Posted by Baltimore Jones
Okay, so what I think I want to do is find the lowest value in the array and then pop that out into the beginning of a new array (alphabetized), repeat until the old array is empty. Is there anything wrong with this logic? And is there anything wrong with this:



alphabetical is the new empty array, words is the original array. x is a variable that equals whichever member of the words array is currently being checked.
That logic is fine and completely normal.
OFFICIAL Ruby on Rails Thread!!! Quote
05-19-2013 , 04:39 PM
Going to thoughtbot's (really awesome rails development shop) Test-driven rails course tomorrow and Tuesday.

I need to get better at writing model tests. Right now my tests are way too dependent on setup, and as a result slow and a pain to write. Hopefully I'll come up with a great understanding of mocking/stubbing, and writing model tests. I'm decent with controller/feature specs afaik.
OFFICIAL Ruby on Rails Thread!!! Quote
05-19-2013 , 09:13 PM
Quote:
Originally Posted by Nchabazam
Going to thoughtbot's (really awesome rails development shop) Test-driven rails course tomorrow and Tuesday.

I need to get better at writing model tests. Right now my tests are way too dependent on setup, and as a result slow and a pain to write. Hopefully I'll come up with a great understanding of mocking/stubbing, and writing model tests. I'm decent with controller/feature specs afaik.
I'm currently working on a project with Thoughtbot's San Francisco office. They definitely know their stuff when it comes to testing. They have some great developers out in Boston. I recommend picking up their Ruby Science book as well. Enjoy!
OFFICIAL Ruby on Rails Thread!!! Quote
05-20-2013 , 03:43 PM
I know this is the Ruby thread, but is Ruby really better to learn job market wise than Javascript?
OFFICIAL Ruby on Rails Thread!!! Quote
05-20-2013 , 04:05 PM
Quote:
Originally Posted by BigPoppa
I know this is the Ruby thread, but is Ruby really better to learn job market wise than Javascript?
Learn both
OFFICIAL Ruby on Rails Thread!!! Quote
05-21-2013 , 09:27 AM
Quote:
Originally Posted by RICHI8
I'm currently working on a project with Thoughtbot's San Francisco office. They definitely know their stuff when it comes to testing. They have some great developers out in Boston. I recommend picking up their Ruby Science book as well. Enjoy!
Really seeing the full TDD workflow was pretty cool (literally doing as little as possible to get tests to get to the next error, then the next, then eventually passing). Also learned a lot of cool ruby/capybara tricks along the way. We're doing a lot of 3rd party API testing today which is something I'm clueless on, so it should be very valuable.
OFFICIAL Ruby on Rails Thread!!! Quote

      
m