Loosely defined link_to may cause problems when overriding url_helper

August 26th, 2008 by Glenn Gentzke

OR “Beware of pick pockets and loose link_to’s”

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:

link_to 'Destroy', some_record, :confirm => ‘Are you sure?’, :method => :delete

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:

link_to ( 'Destroy', record_path(some_record), :confirm => ‘Are you sure?’, :method => :delete )

Refresh that error page and voila! Happy links again! Stricter coders may even group the options with curlies, and that doesn’t hurt either.

Recreating Ely’s Flex 4 List Component Series: Part 3 - Adding Transitions

August 23rd, 2008 by Greg Jastrab

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:

(Either JavaScript is not active or you are using an old version of Adobe Flash Player. Please install the newest Flash Player.)
(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.)

Keep reading for the source…

Read the rest of this entry »

Getting Subclipse to Work in Gandymede (Eclipse 3.4)

August 21st, 2008 by Greg Jastrab

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.

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!

Recreating Ely’s Flex 4 List Component Series: Part 2

August 19th, 2008 by Greg Jastrab

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.

Read the rest of this entry »

Recreating Ely’s Flex 4 List Component Series

August 16th, 2008 by Greg Jastrab

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…

Read the rest of this entry »

using active x and javascript to scan from your web app

August 8th, 2008 by Joseph Jakuta

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).

Read the rest of this entry »

Introducing environmentalist: an intuitive, environment-focused config structure for your rails applications

August 4th, 2008 by John Trupiano

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.

Read the rest of this entry »

Merging Adobe PDF’s and generating a table of contents on the fly using ruby

July 21st, 2008 by Joseph Jakuta

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.

Read the rest of this entry »

Advanced Model Based searches in rails

July 21st, 2008 by Scott Davis

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
  end
 
  def users(u)
    @u = u
  end
 
  def projects(p)
    @p = p
  end
 
  def tasks(t)
    @t = t
  end
 
  def dates(date1, date2)
    @d1 = date1
    @d2 = date2
  end
 
  def clients(c)
    @c = c
  end
 
private
 
  def find_cards
    TimeCard.find(:all, :conditions => conditions, :include => {:task => :project}, :order => :date)
  end
 
  def projects_conditions
    ["tasks.project_id IN (?)", @p] unless @p.blank?
  end
 
  def client_conditions
    ["projects.client_id IN (?)", @c] unless @c.blank?
  end
 
  def date_conditions
    ["date BETWEEN ? AND ?", @d1, @d2] unless (@d1.blank? || @d2.blank?)
  end
 
  def task_conditions
    ["task_id IN (?)", @t] unless @t.blank?
  end
 
  def users_conditions
    ["user_id IN (?)", @u] unless @u.blank?
  end
 
  def conditions
    [conditions_clauses.join(' AND '), *conditions_options]
  end
 
  def conditions_clauses
    conditions_parts.map { |condition| condition.first }
  end
 
  def conditions_options
    conditions_parts.map { |condition| condition[1..-1] }.flatten
  end
 
  def conditions_parts
    private_methods(false).grep(/_conditions$/).map { |m| send(m) }.compact
  end
end

Controller

    search = ExportSearch.new
    search.users(params[:export][:users].join(',')) unless params[:export][:users].blank?
    search.tasks(params[:export][:tasks].join(',')) unless params[:export][:tasks].blank?
    search.projects(params[:export][:projects].join(',')) unless params[:export][:projects].blank?
    search.dates(start_date, end_date)
 
    @time_cards = search.timecards

Creating Your First Custom SkinnableComponent in Flex 4

July 19th, 2008 by Greg Jastrab

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.

Read the rest of this entry »