Getting Setup for Ruby on Rails Development »
Created at: 01.12.2010 21:30, source: Engine Yard Blog, tagged: Technology tips development linux mac rails ruby setup tutorial windows
The Resources for Getting Started With Ruby on Rails seemed to be useful for a lot of people. However, it was a post geared for people who had already setup their computers for development work. So I created a tutorial for those of you who haven't yet set up your computers for Ruby on Rails development. Just go to the Engine Yard Documentation Area, in the tutorials section. There you'll find instructions for setting up your computer, basic git commands, and a step-by-step tutorial on creating an application with Rails 3 and Bundler. Each section is designed to be useful by itself, so if you just want to learn more about Bundler or Rails 3 you can. If you have any feedback on how to improve the tutorials let me know in the comments section. Also, if you want to take a hands-on training course on how to develop a Rails application, you might want to attend the Zero to Rails 3 class which is happening (online) December 20-23.
more »
Sending email: Controllers versus Models »
Created at: 16.11.2009 17:33, source: Robby on Rails, tagged: Ruby on Rails programming development rubyonrails actionmailer models controllers patterns
While reviewing some code recently, I came across controller code that resembled the following.
if @customer.save
CustomerMailer.deliver_welcome_message(@customer)
flash[:message] = "Your account has been successfully created. We've sent you a welcome letter with..."
redirect_to dashboard_path
else
...
endFairly typical Rails code. Nothing alarming here, but I wanted to evaluate the call to the mailer in this scenario. When it comes to sending emails from your application, you can choose to do it from the controller as in the example above or in your models. Our team prefers to do this from our model via a callback as we are considering this to be part of our business logic.
Each time a customer is created, we want to send them an email. This can be moved into the model and resembled something like the following..
after_create :send_welcome_message #, other callbacks..
def send_welcome_message
CustomerMailer.deliver_welcome_message(self)
endThere are a few benefits to doing it this way.
- We can test that this is being triggered within our model specs instead of our controller specs. (we prefer to spend more of our time working within models than controllers)
- We remove the dependency that all requests must be processed through our controllers.
- Example: We may one day create rake tasks that data and want these emails to still be sent out. (We’ve had to do this a few times)
I definitely don’t think doing this via controllers is a bad idea, I just lean towards keeping controllers as dumbed down as possible. This allows us to have less controller code that is focused on passing data to/from models and letting our models do the heavy lifting.
UPDATE: DHH was kind enough to post a more detailed response on his blog.
more »
Using BETWEEN for SQL comparisons »
Created at: 14.11.2009 22:55, source: Robby on Rails, tagged: programming PostgreSQL code sql development PostgreSQL mysql refactoring
Recently, Carlos, suggested that I should start sharing some basic SQL tips that help with performance and/or general usage. I recently came across some code that I didn’t like to read and/or write. For example, let’s take the following…
SELECT * FROM brochures WHERE published_at <= now() AND archived_at >= now()
Essentially, this is pulling back some data WHERE the the brochures are considered published. (We have a project that allows people to manage their brochure launch dates ahead of time.) In fact, in this project, we have no less than 6-8 dates in the database that we’re comparing data on and it’s easy to get lost in the logic when trying to understand it.
Now, there isn’t anything inheriently wrong with how this condition is constuctued. As a matter of personal taste, I find it annoying to mentally parse. Also, I find having to write now() more than once in a WHERE clause to feel like I’m repeating myself.
Read it outloud…
“WHERE the brochures published at date is less than and/or equal to right now AND the archived date is greater than and/or equal to now.”
Who talks like that?
Luckily, there is a better and in my opinion, a more readable way to express this is with the BETWEEN construct in SQL. (postgresql docs, mysql docs)
SELECT * FROM brochures WHERE now() BETWEEN published_at AND archived_at
Let’s read this outloud…
“WHERE the current date is between the published at and archived at dates.”
This sounds more natural to me.
Additionally, you can also do the inverse with NOT.
SELECT ... WHERE now() NOT BETWEEN brochures.published_at AND brochures.archive_at
Remember kids, “code is for humans first and computers second.”—Martin Fowler
more »
Launching Ruby on Rails projects, the video »
Created at: 11.11.2009 20:00, source: Robby on Rails, tagged: Business Ruby on Rails PLANET ARGON Projects agile development clients presentation conference rubyonrails video
For those of you who didn’t make it to Rails Underground in July to witness my mind-blowing talk, Launching Ruby on Rails projects , it appears that Skills Matter has finally posted a video of it online. :-)
The sound levels are really low… but hopefully you’ll find it helpful.
You can also view the slides.
Related Posts
more »
Flash Message Conductor now a Gem »
Created at: 13.10.2009 18:30, source: Robby on Rails, tagged: Ruby on Rails PLANET ARGON gem plugins github development code rubyonrails
We’ve been doing some early (or late… if you’re a half-full kind of person) spring cleaning on some of our projects. One of the small projects, flash_message_conductor, which we released last year as a plugin is now a gem. We’ve been moving away from using plugins in favor of gems as we like locking in specific released versions and being able to specify them in our environment.rb file is quite convenient.
To install, just run the following:
sudo gem install flash-message-conductor --source=http://gemcutter.org
Successfully installed flash-message-conductor-1.0.0
1 gem installed
Installing ri documentation for flash-message-conductor-1.0.0...
Installing RDoc documentation for flash-message-conductor-1.0.0...
You’ll then just need to include the following in your config/environment.rb file.
Rails::Initializer.run do |config|
# ...
config.gem 'flash-message-conductor', :lib => 'flash_message_conductor', :source => "http://gemcutter.org"
endYou can take a peak at the README for usage examples.
We’ll be packaging up a handful of our various plugins that we reuse on projects and moving them to gems. Stay tuned… :-)
more »
