Rails ActiveRecord::Base missing find_all_by_date_range
Hello everyone,
A current project I am working on required finding records within a certain date range. Many other projects I have worked on also required something similar. So, I decided to create a Rails gem to handle this. The gem is available on GitHub. http://github.com/timmatheson/find-all-by-date-range/tree/master
Install
Usage:
I hope this helps anyone else needing this feature of ActiveRecord::Base.
Best regards,
Tim Matheson
Rails JavaScript and CSS file AutoInclude Snippet
Ok so you have a Rails application and it’s growing fast. Your putting complex logic where it belongs, Your partials are DRY, and your using TDD and BDD concepts in your project. The world is yours, your code is bullet poof. Well what about those pesky JavaScript and CSS files? If you have a lot of them they can easily get out of hand and become redundant and duplication becomes a direct result. So how can you DRY it up a bit you ask? With an asset_autoinclude_tag helper. The concept is simple. For each controller/view in your app you design a javascript and or css file with code directly related to the pages rendered by them. In addition to this you name them using the same Rails naming convention as your other files. For instance you have a PublicController you would create a public.css and or public.js file for any css/js code related to that controller. Everything else can go into application.js and application.css.
Heres the code.
Update:
I have moved this into a gem if you would like to use it in your projects. It’s available in my GitHub repository.
git clone git://github.com/timmatheson/asset_autoinclude_helper.git
You can also install the gem by adding GitHub to your gem sources and installing it.
INSTALLATION gem sources -a http://gems.github.com sudo gem install timmatheson-asset_autoinclude_helper-0.1.0
Then to include it in your application just call it in your global layout like this.
<%= asset_autoinclude_tag %>
You can also pass in options for the javascript_include_tag like :cache => true
<%= asset_autoinclude_tag(:cache => true) %>
And thats it. I hope this helps you dry up your code a bit. I know I am probably not the first one to think of this. I plan to make it into a gem soon so check back.
Best regards,
Tim Matheson
1 Year of Ruby on Rails Programming
Over the past year I have made the change to Ruby on Rails as my programming language and framework of choice. The reason is simple, Ruby on Rails manages enough of the tedious tasks faced by most developers fairly easy. With that said it is also safe to say it makes me more productive, and increases the quality of my work. The pros outweigh the cons by far. I would encourage anyone programming in PHP, ASP/ASP .NET, C+, C++, JAVA, or even Cold Fusion to give Ruby on Rails a shot. Most likely you will hit the Rails and never look back, yeah it’s that great. It has now been one year since I originally Installed Ruby, Installed Rails and dug deep into the code. While I am still learning a great deal about some of Ruby’s more advanced functionality I have mastered for the most part the entire framework from unit testing to model associations. If you are just getting started in Ruby I would be glad to answer some of your questions, simply send me an email or comment on this post below.
Best regards,
Tim Matheson
New Ruby on Rails site
I recently deployed a few Ruby on Rails sites to a production server. If anyone wants to check one of them out they can visit Barksnbubbles.com Dog Food, Dog Toys, and Pet Supplies online retailer. If you have any suggestions for the site please let me know.
Best regards,
Tim Matheson
Send emails with ease, Rails Mailers Demystified
Setting up a mailer in Rails can seem like a daunting task, especially to new comers. I found this video and several other resources online to be very helpful in explaining the ins and outs of setting one up. This is a very in depth video explaining how mailers can make life easier for the Ruby programmer. See the screencast!
[via : http://media.railscasts.com/]
UPS Shipping Gem not working - Fixed
Hello everyone,
I recently had the joy of working with the Ruby Shipping gem which allows you to grab shipping rates from UPS and FEDEX. However many people (myself included) have had problems with this gem. The reason is simple the documentation contains misinformation and is causing many developers to bang there heads. I found a solution and would like to share, so here it is.
OK first off make your life easier and create a file
/config/shipping.yml and add your ups account information as shown
below.
#in your config/shipping.yml file ups_license_number: ups_xml_access_key ups_user: ups_username ups_password: ups_password
One important thing to notice is that I am using ups_license_number: as
opposed to ups_account: as shown in the Shipping gem docs :( . This is
what is causing all the trouble. Also note that I am using the xml
access key and not the account number.
Next you need a method to get your quote. Here is a quick one to get you
started.
#in your controller
def ups_quote(to_zip, sender_zip, weight)
#define the parameters for the quote
params ={
:zip => to_zip,
:sender_zip => sender_zip,
:weight => weight,
:prefs => "#{RAILS_ROOT}/config/shipping.yml"
}
#build the shipping gem object
@shipping = Shipping::UPS.new params
end
#in your view
Shipping Quote:
<%= number_to_currency @shipping.price %>
Call for help! Ruby - On - Rails Shipping Gem
Hello everyone, I have been programming in Ruby using the Rails framework for a while now. However I have a situation where I am developing a shipping calculator for my applications using the Ruby “shipping gem”. The problem, at least I think, is the account number, username, password or all of the aforementioned attributes are incorrect. I have verified they are indeed correct and valid. I am getting an object returned to me in my code called the Shipping::ShippingError object. I am sure there is some kind of a message stored inside this object but I cannot access it because I think it is actually a Class. In short what I need to know is how do I, if at all extract the error from this Class? Object? so I can display it to the screen. Below is a code example.
The configuration file “shipping.yml”
#../../config/shipping.yml ups_account: XXXXX ups_user: XXXXX ups_password: XXXXX
The Shipping Controller “app/controllers/shipping_controller.rb”
#app/controllers/shipping_controller.rb
class ShippingController < ApplicationController
def quote
params = {
:zip => 54494,
:state => “Wisconsin”,
:weight => 1,
:sender_zip => 68801,
:sender_state = “Nebraska”,
:prefs => “#{RAILS_ROOT}/config/shipping.yml” }
@shipping = Shipping::UPS.new params
@errors = Shipping::ShippingError
#in the view we will show price like so @shipping.price
end
end
The view file “shipping/quote.rhtml”
Test Shipping This is a test of the UPS shipping code.Output = [<%= @shipping.price %>]
Learn Ruby on Rails and wonder how you ever got along without it
I have been learning Ruby on Rails for a while now and I must say it really is worth the hype. I would like to invite anyone who is interested in learning Ruby and the Rails framework to do so. You won’t be sorry. So what is Ruby on Rails? Well Ruby is an OOP (Object Oriented Programming) language and Rails is a web framework designed by a Danish programmer named David Heinemeier Hansson and 37signals an online web software company. Ruby is the code and Rails is the structure in which the code is organized, generated and maintained. If you have been programming in Java, PHP, ASP, ColdFusion or any other web programming language I would encourage you to checkout Ruby and its friend Rails and see what all the fuss is about. You can see the documentation for Ruby on Rails at http://corelib.rubyonrails.org I would also recommend a few books for beginners who are new to Ruby and or the Rails framework. Some books to get are Agile Web Development with Rails (Second Edition) from Pragmatic Bookshelf and also see Rails Recipes by Chad Fowler. Both books are easy to follow and walk you through the entire design/development process of creating a rails application. Some sites already using the Ruby on Rails framework are http://www.odeo.com, http://www.37signals.com, http://www.basecamphq.com, http://www.highrisehq.com, and many more. You can also download Ruby and the Rails framework by downloading the OCI (one click installer) found here at http://www.rubyonrails.org. If anyone out there has any additional tips for newbies to Ruby (myself included) please feel free to comment.
