I hope most rails dev’s out there take advantage of RESTful routes and the url-generating helpers so readily available these days and actually enjoy them. But for some of you who are lucky enough to inherit a legacy app (you know, 1 year olds) or for whatever reason encounter loosely defined link_to’s [exemplified below], you can easily update the code to avoid some gotchas.
This is what I consider a loosely defined link_to:
It lacks parentheses, option grouping, and most importantly, expects the helpers to generate a specific kind of link (in this case a destroy action) from just the record itself. Now, rails is pretty smart these days and will probably generate the correct link without a hiccup if your app isn’t employing a custom RAILS_RELATIVE_URL_ROOT, or setting skip_relative_url_root => false.
Well, my latest app is. And this is how that loosely defined link_to renders:
ArgumentError in Controller#action
wrong number of arguments (0 for 1)
The stack trace will provide evidence that some thing’s a mess in url_for related to the default_url_options, defined in application.rb (or elsewhere). Rails’ helpers cannot correctly produce a url due to lazy linking.
So, make your code more readable and keep the helpers happy and define your link_to’s like this:
In Part 2 we added hovered and selected states to the ItemRenderer for the list items. In this part we’ll add some transitions to make the list look more like an Accordion. Since screenshots won’t do the example justice this time, I’ll show a screencast I made demonstrating the result first:
(Sorry for the embed being cutoff, still figuring out the params to this word press plugin. Click through for the full embed on its own page.)
I just upgraded Eclipse to 3.4 (Gandymede) since the latest upgrade to Flex Builder included support for Gandymede. I did my typical install by extracting the Gandymede tarball and then installed Subclipse through the Software updates (now in Help -> Software Updates…).
It looked like everything installed okay but then when I tried to do an update in an existing project I got an error:
"Unable to load default SVN Client"
The key is to include the SVNKit Adapter JavaHL Adapter when you install Subclipse:
Include JavaHL when installing Subclipse.
Hope that saves some people some time.
NOTE: Thanks to Mark for pointing out the recommended usage of JavaHL instead of SVNKit!
In Part 1 of this series we learned how to create an ItemRenderer for a List in Flex 4. I wanted to get through 2 steps tonight, but only have the code for the next step finished. This code creates the item renderer seen at ~4:20 of Ely’s video.
If you haven’t seen Ely’s video on Adobe TV about improving the designer/developer workflow (which is an updated version of what he infamously previewed at MAX last year), you should probably check that out to see what the goal of this series is.
I’m going to attempt to go through the steps and recreate what he demonstrated, which was to take a simple list and iteratively transform it into a rich, accordion-like interactive list. To get started, be sure that you’re setup to compile Flex 4 code and that you have Flash Player 10. Here we go…
In the app I had been working on users had to perform a great amount of scanning. In the first few iterations this was done manually, which, of course, lead to lots of user error (namely scanning documents at high resolutions, which clogged the system). It was decided that it was best if our app to control the scan settings for most users. So we found three possible Active X controllers available to allow for this functionality. CianSoft, VintaSoft, and ChestySoft. After a little research we found that VintaSoft didn’t quite meet our needs and that CianSoft’s TwainX controller and ChestySoft’s were eerily similar (it turns out that each company is run by a brother and both products were just different flavors of the same one). In the end ChestySoft was the one we went with because it allows you to perform posts of the scanned data to the server (and the guy that runs the company is super responsive when you have questions).
A couple of months ago, I wrote an article (Better setup for environments in rails) discussing the standard set of changes we make to the config structure of each of our rails apps.
The primary motivation for me to make these changes stemmed from the need to have several deployable environments. The standard set of rails environments (development, test, production) simply just don’t cut it for me. It’s important for us to be able to deploy to staging, demo and even production-test environments. When including server configurations (e.g. a Passenger config snippet, or a mongrel_cluster config snippet), I’ve often had to use unique configurations for each deployable environment. Consequently, my config/ directory quickly became polluted with files such as: apache_prod.conf, apache_staging.conf, apache_demo.conf. Furthermore, it also requires special care when deployment comes around.
So let’s say you have some random PDFs and what you want is one PDF that includes all of the original PDF files and a table of contents listing all of the files and the proper page numbers. Well in Ruby it is not too hard to put this together. There are a wealth of plugins, gems, and other ruby software available for manipulating and creating PDFs (a thorough list can be found here - http://wiki.rubyonrails.org/rails/pages/HowtoGeneratePDFs). To get this project up and running we are going to use two PDF::Writer (http://rubyforge.org/projects/ruby-pdf/) and PDFTK (http://www.accesspdf.com/pdftk/) - though if you want to get fancier and also include text, html, or xml documents you can use PDF::Htmldoc (http://htmldoc.rubyforge.org/) which requires Htmldoc to be installed. Before I do get started though, I also have give thanks to George Anderson over at Benevolent Code who wrote a lot of similar code on the project which provided me with some great examples.
After watching a railscast episode on advanced searching I thought I would give it a try. So I came up with a slightly modified version that would handle my search.
Model
class ExportSearch
def timecards
find_cards
enddef users(u)@u = u
enddef projects(p)@p = penddef tasks(t)@t = t
enddef dates(date1, date2)@d1 = date1
@d2 = date2
enddef clients(c)@c = c
end
private
def find_cards
TimeCard.find(:all, :conditions=> conditions, :include=>{:task =>:project}, :order=>:date)enddef projects_conditions
["tasks.project_id IN (?)", @p]unless@p.blank?
enddef client_conditions
["projects.client_id IN (?)", @c]unless@c.blank?
enddef date_conditions
["date BETWEEN ? AND ?", @d1, @d2]unless(@d1.blank? || @d2.blank?)enddef task_conditions
["task_id IN (?)", @t]unless@t.blank?
enddef users_conditions
["user_id IN (?)", @u]unless@u.blank?
enddef conditions
[conditions_clauses.join(' AND '), *conditions_options]enddef conditions_clauses
conditions_parts.map{ |condition| condition.first}enddef conditions_options
conditions_parts.map{ |condition| condition[1..-1]}.flattenenddef conditions_parts
private_methods(false).grep(/_conditions$/).map{ |m| send(m)}.compactendend
It took me a couple of days to get to my next Flex 4 example, but here we finally are. I wanted to try making a component which had optional SkinParts, so I came up with the following example (get the source). For those who don’t know, Flex 4 targets Flash Player 10 so you’ll need that in order to run the SWF.
In this example we will build a component called QuestionAndAnswer which will include a text field containing a question, a check box, and a text field containing an answer to the question. The check box and answer are both optional, so if the Skin file doesn’t include those SkinParts, they won’t be a part of the view. If they are included, then clicking the check box will show the text field containing the answer. Let’s see what the code looks like.