How to override ‘Create New’ for activescaffold associations

In the helper file, ie tablenames_helper.rb, override the render_action_link method

 def render_action_link(link, url_options, record = nil, html_options = {})
    if link.parameters[:association] == :my_association
       # special handling here
    else
       super  # in case you have other associations for which you do want the default behavior
    end
 end

This confounded me for a while as it was easy to create a helper to override the link to associated records, but if the records did not yet exist the ‘Create New’ appeared hardcoded. After inspection of ./bundler/gems/active_scaffold-45451d963672/lib/active_scaffold/helpers/list_column_helpers.rb and ./bundler/gems/active_scaffold-45451d963672/lib/active_scaffold/helpers/view_helpers.rb the above override became apparent. Is there an easier way to determine this sort of thing?

The problem with important authors…

…is that they are too important to take time for the grunge work that makes a technical book useful.

Agile Web Development with Rails is essentially a book-length tutorial, and imho not worth either the money or time. The entire book is narrative. It admits as much in the introduction: “This book isn’t meant to be a reference manual for Rails…reference manuals are not the way most people learn.” Maybe so, but they are extremely helpful productivity tools when trying to do actual work! (The narrative itself is so patronizing and self-aggrandizing its painful to plow thru, though probably does have some value if you can stomach it.) An auto-generated code API is no replacement for a human edited reference manual with context. It seems Rails requires you to ‘read the code not the docs’ in order to do anything nonstandard, which works, but…not exactly productivity enhancing as advertised.

Browsing a good reference lets you see immediately the structure of a framework.

PHP.net is beautiful and so efficient, I’ve never bought a PHP book either – but for the opposite reason I’d advise not buying this one.

case of the missing layout

After a bit of refactoring of one of my controllers in a Rails3 app, the layout mysteriously disappeared, with

Rendered vendor/plugins/active_scaffold/frontends/default/views/list.html.erb (188.5ms)

replacing

Rendered vendor/plugins/active_scaffold/frontends/default/views/list.html.erb within layouts/application (192.1ms)

in the Rails debug output. Turned out to be a simple error – I added a routine to initialize some instance variables and forgot the ’super’ at the end to call the parent class initializer:

def initialize
   ... my instance vars ...
   super
end

Ruby yes, Rails…not so much

The thing that is the most annoying about rails, after the general atmosphere of one-upsmanship, is that the general arrogance about being the best way to do things seems to lead to lack of good reference documentation. Tutorials for specific ways to do a particular task in ‘the Rails way’ abound, but reference docs are limited to the actual api for the code. Method-level references with clear explanations are just..nonexistent.

Everything is eventually possible, with much reading of code and blog posts, but clarity as to what is possible in a given context – missing.

Ruby is a beautiful, elegant language. Rails popularized the idea of scaffolding, and yes, if you want to do the standard shopping cart of database items you are done in 8 minutes. However….if you want to do something else entirely, every step needs to be painfully discovered by deep introspection….

Of course Joel says this so much better: Joel on Rails

try reinstalling rake instead…

Using a shared gemset between two projects may be a bad idea, not sure. After installing vhochstein’s Rails3 branch of ActiveScaffold in the second project (tho not sure that was the key factor), I started getting this error on running rake db:migrate:

“no such file to load — net/https. Try running apt-get install libopenssl-ruby”

Tried many of the suggestions at http://www.ruby-forum.com/topic/90083 without help…finally, decided it was rake at fault, just ran

gem install rake

(even though it was already installed), and the error went away…

Ruby beats Perl for UTF-8 handling

Just had to write a script to do some processing on a tab-delimited file that contained some Hebrew UTF-8 chars, including a json chunk containing some Hebrew. Major headache with Perl – either got ‘wide char in subroutine’ errors, or escaped codes in the JSON. Needed to compare the UTF-8 tab-delimited fields with specific pieces of JSON, and have them both handled as UTF-8. Tried use utf8; binmode(STDIN, ':utf8') and various other permutations, but couldn’t get the output to look the way I wanted while keeping all the subroutines happy.

Implemented the same thing in Ruby, and it just worked. I’ve been a Perl girl for years, but am leaning Ruby…

Varnish -drop in website cache / accelerator

Check it out – Jeff Su, a developer on our team at Factual.com has had really good results using Varnish, written up here:

A Practical Guide to Varnish

For sites that need to ramp up suddenly, this could be a lifesaver…

setting JAVA_HOME

The instructions at http://www.cyberciti.biz/faq/linux-unix-set-java_home-path-variable/ are slightly out of date or incorrect. Instead of setting

export JAVA_HOME=/usr/lib/jvm/java-6-sun-1.6.0.22/bin/java # do NOT do this

as you might expect from their instructions, you should

export JAVA_HOME=/usr/lib/jvm/java-6-sun-1.6.0.22/

rpm complaint about NSS/NSPR headers really looking for sechash.h…

Needed to build a recent version of RPM from source. When running ./configure for rpm-4.8.1, I ran into the ‘configure: error: missing required NSPR / NSS header’ error referenced at

http://lists.rpm.org/pipermail/rpm-list/2009-May/000253.html

The solution there is good but incomplete, a peek into the configure file reveals that they are really checking for ’sechash.h’ which is in the nss-devel package. After doing a

yum install nss-devel
as well as
yum install nspr-devel

then I can successfully run

./configure CPPFLAGS=”-I/usr/include/nspr4 -I/usr/include/nss3″

(well, almost successfully…now I am on to the next error message about a Berkeley Db directory not present…if that seems tricky as well will post a solution here, if straightforward I won’t bother…)

“Ling” – an idea for a Linguistic programing language

Here’s a thought on how to code to spec:

Write a clear, concise design document for your application that can be understood by users and domain experts. Use brief, simple language as much as possible with some preferred constructs.

Then write code that makes the design document run.

Seriously – why not? It seems to me code should be more about language constructs, building powerful syntax for expressing functionality. So why not build up the syntax that makes a design document into a program?

I was thinking about the old LOGO functional language from Seymour Papert, the one with turtles that you could teach to do things ‘to square: forward 10, turn 90, forward 10…’ then ’square, forward 10, square, …’ etc. The logical conclusion seems like it should bring us closer to bridging the gap between language and code, or at least lead to more libraries of syntactical constructs. OO is fine for nouns but it doesn’t lend itself well to creating new verbs, let alone sentence structures.

Ah well – back to implementing my HLD manually…