time.onrails.org Launches
time.onrails.org is a free time tracking application written by Daniel Wanja of Nouvelles Solutions. I’ve used it some in development and it’s a very handy tool. If you bill by the hour head over and check it out.
time.onrails.org is a free time tracking application written by Daniel Wanja of Nouvelles Solutions. I’ve used it some in development and it’s a very handy tool. If you bill by the hour head over and check it out.
Bruce Williams has release a nice plugin to access pdftex using Rails Views to generate PDFs:
http://codefluency.com/pages/rtex
pdftex is probably already installed if you are on a *nix system, but if on Windows you’ll need to install it. I’m in that category (for the moment) and found it pretty easy to get going.
There are many LaTeX distributions and most of them now include pdftex. I used one called proTeXt that promised to be comprehensive and easy to install. It seems to be both so far:
It’s a substantial download of about 415 MB. I don’t know if there are others that are lighter – probably so. This one includes 2 different editors along with a number of other extras. I was interested in LaTeX itself as I’ve heard about it over the years and just never had a good reason to dive in and check it out. So I grabbed proTeXt as it seems it will allow me to dig in a bit. I used to work in the graphic design world and had a particular liking for working with text, so I want the full tour.
After you download, extract the archive to a temp directory. Then open up the directory structure to protext/install and open the PDF for your language. The rest of proTeXt is actually installed by use of this PDF. It’s a pretty nice system really – you get a couple paragraphs on why you are about to do what you are about to do, then a link is presented that starts the next install. It’s very clear about what can be skipped (like those two editors) and what is essential. Pretty cool, really.
Install the plugin to a Rails app and fire it up. Bruce has a sample controller method – just be sure to add ‘renderwithoutlayout’:
def mypdf @time = Time.now renderwithoutlayout end
The ‘rtex’ view (mypdf.rtex) is:
documentclass[11pt]{article} begin{document}
The time is <%= @time %>.
end{document}
This is kind of a throwback to me. In the early 90s I worked to convert a publishing system at a newspaper from using a linotype typesetting machine to using Macs and QuarkXPress (version 3 was just about to come out – woo!). This looks kind of like the markup that our typesetter understood. It should work well for generating documents, but I’m not sure I’m ready to start inserting LaTeX into my writing. But for generating documents it looks to work well, and it seems you have about as much typographic control as those old typesetters did, which was really a pleasure to see, if not to mark-up.
Next step is to try creating a table. I’ll post a sample when I have one.
Last summer I developed my first Rails application under a very tight deadline. I cut a few(!) corners and one was not creating a link from my Person table to my Team table for the team coach.
So I’m trying to clean up after myself a bit. It turns out that I can get about 90% of the way there for just a few quick lines of code:
class AddFieldsToTeam < ActiveRecord::Migration
def self.up
add_column :teams, :coach_id, :integer
add_column :teams, :asst_coach_id, :integer
Team.reset_column_information
@teams = Team.find(:all)
@teams.each do |t|
c = Person.find_by_full_name t.coach
ac = Person.find_by_full_name t.asst_coach
if !c.nil? || ac.nil?
t.coach_id = c.id unless c.nil?
t.asst_coach_id = ac.id unless ac.nil?
t.save
end
end
end
def self.down
remove_column :teams, :coach_id
remove_column :teams, :asst_coach_id
end
end
Here’s the findby_fullname:
def self.find_by_full_name(fn)
name = fn.split
find(:first, :conditions => ["void = 0 and first_name = ? and last_name = ?", name.first, name.last])
end
That’s just too easy.
migration railsIf you’re running a recent rails app and are on a host like DreamHost where the RAILS_ENV isn’t set, you’ll need to use this to run your migrations:
rake environment RAILS_ENV=production migrate
Otherwise you’ll get this:
Can‘t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock‘
Or you’ll connect to your development database if you have one configured.
Rails 0.14.4 RC5 is out. You can get it now with Edge Rails or soon with RubyGems.
If you’re interested in staying really on top of this, you can set up an account at RubyForge.org and click the ‘monitor’ icon in the project summary page. You’ll get an email when new versions are available.
UPDATE: As you probably know by now, you can update with
gem install rails --include-dependencies
If moving up from another 0.14.x, you should be done. Do not call ‘rails’ over your application to upgrade. One nice feature with the 0.14 series is that a lot of the common code (e.g. everything under /script) is moved out of your application’s directory. There will be less updating to do to your application.
If you’re upgrading from an earlier version, here’s the guidebook.
While on the subject of the new .rjs templates, Liquid is an optional templating system based on Django’s templates and implemented by Tobi of Typo fame. I haven’t tried them yet – this is a sort of ‘note to self’ to give them a whirl one of these days. .rhtml is great, but it’s nice to have options.
“Marcel Molina Jr. recently announced that RJS templates would not be included in the 1.0 release of Rails, but that they might include them as a plugin.
I thought that it was about time for me to learn the plugin system in Rails anyway, so I packaged up all of Sam Stephenson’s hard work on the RJS templates from changesets 3078 and 3084 and turned it into a plugin.”
Since it was announced that the new .rjs templates wouldn’t be shipping with Rails 1.0, Cody Fauser went ahead and packaged them up as a plugin. You can use the plugin with the rails stable trunk or the 0.14.3 gem.
.rjs templates are well worth looking into if you do any ajax in your views. Thanks Cody!
I got a bad case of code formatting envy when I saw Cody’s post on .rjs templates. I’ve been happily running a somewhat dated Typo install since it basically worked, but when I read about the new (to me anyway) Macros, I knew it was time to make the leap.
In the past I’ve downloaded the source to my local machine, done whatever config there is, then uploaded the final pieces to my account. This time I thought I’d try the direct route. I made a backup of my typo directory and database, then did a svn checkout directly to my web account:
svn checkout svn://leetsoft.com/typo/trunk typo
I cd’d into the new typo directory and ran
rake migrate
But got these nasty errors.
So I panicked for a minute. DreamHost has upgraded to Rails 0.14.3, which is great, but I needed something newer, fresher, edgier. So I moved to my typo/vendor directory and
svn co http://dev.rubyonrails.org/svn/rails/trunk rails
And that was it! I ran migrate again and it worked like a charm. Now I have Trunk Typo on Edge Rails and it’s working great.
This is cool. Just when you think those Rails guys are about out of tricks, they pull this out of their hat.
If you’ve used the groovy AJAX tools in Rails much, you’ve probably hit the point where you have to update two elements on a screen. It gets ugly pretty quick, with calls to “evaluateremoteresponse” and “updateelementfunction” (as best I recall) and it really gets to be unclear what is doing what to whom and when.
Here’s a little addition/clarification to the demo that Cody posted.
In a controller, add these:
def fox
@header = "A Nice List of Animals"
end
def add
@new_item = params[:arg]
@header = "All Your List Are Belong To Us!"
end
def remove
end
Your fox.rhtml would look something like:
<h1 id=’header‘><%= @header %></h1>
<ul id=’list‘>
<li id=’dog‘>Dog</li>
<li id=’cat’>Cat</li>
<li id=’mouse‘>Mouse</li>
</ul>
<div><%= link_to_remote("Add a Fox!",
:url =>{ :action => :add, :arg => "Fox" }) %></div>
<div><%= link_to_remote("Nuke the Cat!",
:url =>{ :action => :remove }) %></div>
Your add.rjs goes in your views directory next to the other views for that controller:
page.insert_html :bottom, ‘list‘, content_tag("li", @new_item)
page.visual_effect :highlight, ‘list‘, :duration => 3
page.replace_html ‘header‘, @header
And also toss in a remove.rjs for fun:
page.visual_effect :shrink, ‘cat‘, :duration => 1
And Voila! This is still a simple example, but you can see that it will sure help clean up Ajax-driven pages a whole lot.