Workshop Dog
Workshop Dog is a free events calendar for dog training workshops and group lessons.
more »
Active Record Find Methods
Active Record find methods for selecting range from http://charlesmaxwood.com/notes-from-reading-activerecordbase/
Student.find(:all, :conditions => { :grade => 9..12 })
return a range
Student.find(:all, :conditions => { :grade => [9,11,12] })
will return an "in()"
Programming: acts as taggable on load order plugins Rails to_param
by bseanvt
1 comment
Hacking Rails Plugins
Using the Acts as Taggable On plugin to add categories to a model class, I wanted to override the to_param method and place the name attribute in the url. The plugin, installed as a gem, source shouldn’t need to be hacked in order to accomplish this. The solution is to add a plugin into the RAILS_ROOT/vendor/plugins directory and append the plugin name with _hack. This will, because of an alphabetical load order, allow you to reopen the any class in the plugin. In my example
# RAILS_ROOT/vendor/plugins/acts_as_taggable_on_hack/init.rb
Tag.class_eval do
to_param
"#{id}-#{name.gsub(/[^a-z0-9]+/i, '-'/)
end
end
Got this tip from http://errtheblog.com/posts/67-evil-twin-plugin.
Programming: /etc/hosts 127.0.0.1 80 django domain hexxie.com localhost Rails resolve subdomain wildcard
by bseanvt
8 comments
Setup Wildcard Subdomain on Localhost for Development Work without /Etc/hosts TomFoolery
Step 1.
Open up your browser and visit http://www.hexxie.com. You can also go to anything.hexxie.com and everything.hexxie.com, which will resolve to your local machine (assuming it’s localhost at 127.0.0.1).
How it works
Super simple. I just pointed hexxie.com and *.hexxie.com to 127.0.0.1, which is your localhost address. If you’re on Rails just append the port number as usual. http://hexxie.com:3000 or on Django http://hexxie.com:8000. Or you can always fire those guys up on port :80 with sudo ./script/server -p80 for Rails
or sudo django-admin.py runserver 80
To set up your own just configure DNS to point your domain to 127.0.0.1 for the IP address. No more futzing with /etc/hosts
Originally got this tip from http://tbaggery.com/2010/03/04/smack-a-ho-st.html who has created his own service at smackaho.st
The word “Hexe” is German for “Witch”. I have a dog named “Hexxie” after the German word and that is the origin of the domain name hexxie.com, in case you’re wondering.
Ruby on Rails: builders custom tag builder extending forms label Rails template text field
by bseanvt
1 comment
Extending Rails Form Builders
Extending forms in Rails is simple and will greatly reduce the amount of code in your views. This example is taken right from the Agile Web Development book on Rails(2.1.*) with one minor tweak. I want to pass a label argument along with the field name so that I can display a more human friendly string to represent the form field.
# RAILS_ROOT/app/helpers/custom_tag_builder.rb
class CustomTagBuilder < ActionView::Helpers::FormBuilder
def self.create_tagged_field(method_name)
define_method(method_name) do |label, *args|
label_name = args.first.blank? ? label : args.first[:label] # my change
@template.content_tag("p",
@template.content_tag("label",
label_name.to_s.humanize, :for => "#{@object_name}_#{label}") +" <br/> "+ super)
end
end
field_helpers.each do |name|
create_tagged_field(name)
end
end
You can then use this in your views
form_for @your_model, :builder => CustomTagBuilder do |f| f.text_field :fullname f.text_field :email, :label => "Email (will not be published)"
My change tests for the presence of a label argument otherwise using the name of the form field/model attribute. In this case the fullname attribute will be outputted as “Fullname” while “Email (will not be published)” as the label for the email text field.
Placing an Authenticity Token in a Rails Form
<%= hidden_field_tag :authenticity_token, form_authenticity_token %>
Documentation: api dictionary Documentation jquery mac os x Rails yui
by bseanvt
leave a comment
Ruby on Rails, jQuery and YUI API Docs Available as Mac OS X Dictionary Binaries
I came across an awesome tool this morning. Priit Haamer has chunked Ruby on Rails, jQuery, and some of YUI documentation into native Mac OS X dictionary binaries. This lets you search those API docs from Spotlight, TextMate, any application that uses the dictionary app!
I have tested the Ruby on Rails API within TextMate. Hover over any function and hit ctl+cmd+d and a little popup will give you a glimpse at the API docs. Seems like a nice alternative to ACK or the normal TextMate function lookup.
More information and installation instructions are available at Priit’s site http://www.priithaamer.com/blog
Here is a nice video of the tool
A Through Z
How to print the alphabet in Rails very easily.
("A".."Z").each {|letter| link_to letter, "/#{letter"}
"A".upto("Z") {|letter| link_to letter, "/#letter"}


