All You Need is CRUD?

Posted almost 8 years back at The Hobo Blog

DHH, as you probably heard, has learnt to stop worrying and love the CRUD. I’m very much in agreement. The idea of replacing the actions add_member and remove_member (or would that be join_group and leave_group?) with Membership#create and Membership#destroy was the final light switch that got me to a place I’d been striving for.

The generic controller. A standard implementation of the CRUD actions that can be used out-of-the-box in a large majority of cases.

The idea is that the concrete controllers that make up an application will need no custom code at all – just a few declarations: I need an auto-completer for this attribute, an ajax-setter for that one… I don’t see why this can’t be done.

Of course if an application needs to do something unusual, then sure you might want a custom action or two. But a huge number of apps are really nothing more than a web-interface to a database, and nearly all apps have at least some parts that fit this description.

There are a couple of challenges though. Firstly, what should these standard actions render? It’s all very well to have a single URL that you hit to, say, create a new event in your calendar, but depending on where in your app you’re coming from, you’re likely to want a different page (or ajax update) to follow.

Simple answer - parameterise it. Have the browser request “create me a new event, then refresh parts a, b, and c of my page”. That functionality is now part of Hobo and seems to work great. As well as getting us closer to a fully generic controller, this idea has also yielded a very simple approach to ajax.

Another problem I’ve hit is that sometimes an application feature requires a whole graph of related models be created in one go. The solution to that one has been to extend the way ActiveRecord handles the hash you pass to MyModel.new. With Hobo’s ActiveRecord extensions, that single call to new can set up arbitrary relationships with other models, either existing or new.

This post is light on technical details (all will be revealed), but it sets the stage for what I want to waffle about next – Hobo’s support for ajax. I think Hobo’s approach will make ajax programming easier than with anything else out there.

Just had a good week delivering a Rails training course for Skills Matter in London, but of course that meant little progress with Hobo. Next week it’s full steam ahead!

250 RadRails Templates

Posted almost 8 years back at schadenfreude

Dr. Nic has converted all of the Textmate snippets to RadRails templates. All 250 of them.

RADRails will include these templates in the new version 0.7.2 scheduled to push next week, but if you cant wait, download them now from Dr. Nics new site, www.radrailstemplates.com.

250 RadRails Templates

Posted almost 8 years back at schadenfreude

Dr. Nic has converted all of the Textmate snippets to RadRails templates. All 250 of them.

RADRails will include these templates in the new version 0.7.2 scheduled to push next week, but if you cant wait, download them now from Dr. Nics new site, www.radrailstemplates.com.

250 RadRails Templates

Posted almost 8 years back at schadenfreude

Dr. Nic has converted all of the Textmate snippets to RadRails templates. All 250 of them.

RADRails will include these templates in the new version 0.7.2 scheduled to push next week, but if you cant wait, download them now from Dr. Nics new site, www.radrailstemplates.com.

RJS templates without the R!

Posted almost 8 years back at Luke Redpath - Home

In terms of making AJAX applications easier to develop, RJS templates are one of the most significant additions to Rails over the past year. They were far more elegant than adding AJAX callback hooks throughout your main RHTML templates (which was just plain ugly) and it let you get access to your model data in your JavaScript response easily. For many, the killer feature was being able to write your AJAX response behaviour in Ruby — one language to rule them all. The forthcoming Simply Helpful plugin takes this even further. However, not everybody is as keen on RJS templates and a new plugin by Dan Webb seeks to change the way you write your AJAX functionality in Rails.

Dan and I have had several discussions over a few beers about RJS and Dan being the JavaScript wizard that he is was of the opinion that writing JavaScript behaviour in Ruby was an abstraction too far. His reasoning was simple: JavaScript when used correctly can be a powerful language and adding a Ruby API on top was an extra layer of magic that just wasn’t necessary. Whilst he made a fair point, I still felt that RJS was infintely better than the old way of doing things and that its pros outweighed its cons…until now.

The main con with RJS is that you are depending on another layer and if that layer isn’t complete you have to revert to JavaScript anyway — you can do this in RJS by using page.call but this is ugly and really highlights its shortcomings. It would probably be fair to say that RJS as it is currently implemented, is a leaky abstraction. Not only that, but RJS is tightly coupled to the Prototype JS library and Scriptaculous – for fans of one of the many other JS core/effects libraries out there you are left with either the option of trying to port RJS to your library of choice, using page.call commands or resorting to the old callbacks method.

I was somewhat blinded by the “cool” factor of writing my JS behaviours in Ruby — after all I’m a Ruby programmer first and a JavaScript guy second. But when I really think about it, all RJS does is limit me when I want to do anything outside the simple cases that RJS caters for. But the idea of returning a behavioural response from a template is an excellent one and that has always been the overriding factor for me.

As of today, a new option has become available in the form of a new plugin courtesy of Dan – MinusR: RJS templates, without the R! Thats right, RJS templates that let you write your behaviour in JavaScript instead of Ruby. Not only that, but you can still get access to your model data (or other things such as helpers) by embedding ERb — MinusR comes with a js() helper method that encodes the output of your ERb output block in JSON. And finally, you can use whatever JS library you like.

So check it out and start embracing JavaScript. Also check out Dan’s blog post about MinusR.

The REST Dialogues

Posted almost 8 years back at Ryan Tomayko's Writings

I'm not sure what it is about REST that requires use of The Dialogue but it worked for me and, judging by Sam’s Meme Map, it’s definitely working in Duncan Cragg’s The REST Dialogues and Pete Lacey’s The S stands for Simple.

If Dialogues aren’t your style, Bill Higgins has a new two part series on Ajax and REST: Part 1 and Part 2.

It’s times like these I wish I was still in heavy research, discovery, and advocacy mode with REST and Web Architecture. I've been spending the past year deep in the database, which feels like the other side of the development universe.

Installing Rails and Mongrel on a Shared Host

Posted almost 8 years back at schadenfreude

In some situations you may find yourself needing to install mongrel or other ruby gems in a shared environment and the documentation out there for taking on such an enterprise is quite lacking.

Today I went through the trouble and figured out how.

Installing Rails and Mongrel on a Shared Host

Posted almost 8 years back at schadenfreude

In some situations you may find yourself needing to install mongrel or other ruby gems in a shared environment and the documentation out there for taking on such an enterprise is quite lacking.

Today I went through the trouble and figured out how.

Installing Rails and Mongrel on a Shared Host

Posted almost 8 years back at schadenfreude

In some situations you may find yourself needing to install mongrel or other ruby gems in a shared environment and the documentation out there for taking on such an enterprise is quite lacking.

Today I went through the trouble and figured out how.

Javascript Validations and Encryptions — how to use javascript encryptions in rails.

Posted almost 8 years back at Ajax on Rails


A Quick Review on ENCRYPTIONS
We all are very familiar with the ruby encryptions we usually implement SHA1 or MD5 in our rails applications. In my ongoing project i have been through encryptions in little bit more depth.
MD5 was the most widely used hash algorithm, it converts a string into a 32 characters long hashed key. Then comes the SHASecure Hash Algorith. SHA is a series of hash algorithms and its first member is SHA-0 however soon its usage was replaced by the successor SHA-1 and thereafter SHA-0 was never used again. The current members to the SHA series are SHA-1, SHA-224, SHA-256, SHA-384 and the latest SHA-512. At this moment SHA-1 is considered to be the successor of MD5 because of the usage and popularity statistics.
However SHA-224, SHA-256, SHA-384 and SHA-256 are collectively known as SHA-2 series.
Till yet SHA-0 and SHA-1 have been reported attacked but no attack has been found on SHA-2 series.(took from wiki)

Here we will discuss the javascript and ruby based encryptions for SHA-256 only.

Javascript Encryption in Ruby on Rails

If you need to encrypt the password at client side in ror or any other web-based form submission so that the real password string can not reach the server you can you can download the Javascript Encryption files from here. There is all collection of the javascript encryption files available in the above archive. You will not need all of them. Put the file sha256.js in the /public/javascripts/ directory of your rails application.
Now lets take the example of Reset Password where encryption is a must.
This is how you can make your view say reset_password.rhtml


<%= javascript_include_tag 'sha256' %>
<script type="text/javascript">
// <![CDATA[
  function hashPassword() {
  reg = new RegExp(/^(?=.*\d)(?=.*([a-z]|[A-Z]))([\x20-\x7E]){8,40}$/);
  if((reg.test($F('password')))&&($F('password')==$F('password_confirmation'))){
  document.reset_password.realpass.value = hex_sha256($F('password'));
  $('password_confirmation').value = '';
  $('password').value = '';
  Element.hide("reset_password");
  Element.show("updating");
  return true
  }
  else{
  $('errors_in_pass').innerHTML = "Password should match confirmation.<br />Password should contain at least one letter and one integer.<br />Password length should be 8 to 40 characters long.<br />";
  $('password_confirmation').value = '';
  $('password').value = '';
  return false
  }
  }
// ]]>
</script>
<h1>Change Password</h1>
<div style="display:none;" id="updating">Updating Password</div>
<div id = "reset_password">
<div style = "color:red" id = "errors_in_pass"><%= flash[:notice] %></div>
<% form_for :person, @person, :url => {:action => "reset_password"}, :html => {:name => "reset_password",:onsubmit => "return hashPassword()"} do |f| %>
<%= hidden_field_tag 'realpass' %>
        New Password
        <%= f.password_field :password, :id=>"password", :class => "field text", :value=>"" %>
  Confirm New Password
        <%= f.password_field :password_confirmation, :id=>"password_confirmation", :class => "field text", :value=>"" %>
  <%= f.submit_tag "Continue" %>
<% end %>
</div>

However it may possible that a user have disabled the javascript of the browser. In that case we will need to add the encryption at server side too. In rubyonrails we can easily handle the SHA256 encryption for let say password by adding the code


require "digest/sha2"

hashed_password = Digest::SHA256.hexdigest("password_string")

in an appropriate position in the controller.

Rails on Gentoo

Posted almost 8 years back at benmyles.com - Home

I’ve recently become something of a Gentoo fan. Just one aspect of what makes Gentoo such a great Linux distribution is the Portage package system. Using Portage, you can define USE flags that specify what dependencies to include with your packages. For example, if I want to install GraphicsMagick with lcms support, I just make sure lcms is one of my USE flags. Of course, this flexibility is achieved by compiling everything from source, but Portage makes that a cinch.

I’d like to guide you through setting up a fresh, minimal Gentoo install with a complete Ruby on Rails environment. No fuss, no pain. I’ve used the recipe below to setup multiple Gentoo slices from Slicehost.


# emerge --sync
# emerge portage

# echo 'USE="lcms apache2 gif imagemagick innodb jbig \
jpeg jpeg2k mysql pdf perl php png postgres python \
ruby sqlite3 ssl svg tiff truetype unicode wmf xml \
xpm pcre"' >> /etc/make.conf

# echo "dev-ruby/rmagick" >> \
/etc/portage/package.keywords

# echo "media-gfx/graphicsmagick" >> \
/etc/portage/package.keywords

# emerge --update --deep --newuse world

# emerge app-admin/sudo vim gentoolkit mysql \
postgresql perl python ruby openssl rubygems \
subversion graphicsmagick sqlite libpcre

# gem install -y rmagick
# gem install -y rails
# gem install -y mongrel
# gem install -y mongrel_cluster
# gem install -y BlueCloth
# gem install -y RedCloth --version '=3.0.3'
# gem install -y mysql
# gem install -y postgres
# gem install -y tzinfo
# gem install -y sqlite3-ruby

Smuggle

Posted almost 8 years back at

I needed to mirror some galleries from one smugmug account to another. I thought about doing it manually but that idea seemed like way too much work.

I found a python script by rutt that did a little bit of what I wanted and went to work hacking. This resulted in smuggle.py that may be useful if you ever have to programatically interact with the smugmug APIs. It will probably evolve as my needs change and as I actually start to learn python.

The source is available from subversion. Enjoy!

svn co http://www.realityforge.org/svn/code/smuggle/trunk/ smuggle

Shackled But Free

Posted almost 8 years back at Ryan Tomayko's Writings

Java going Free is a big deal. Whether it turns out to be a big deal for the Java community is yet to be seen but I know with absolute certainty that it was a big deal for Sun and it will surely have an impact on many Linux and BSD distributions.

With regards to Sun, I'm honestly having a hard time figuring out how they pulled this off. To put things into perspective, I've had the privilege of placing various software projects under Free licenses and I've wanted to go GPL with all of them. Each of these projects were much smaller in scope and influence than Java. The number of projects I'm involved with that are GPL licensed: zero.

Licensing GPL is hard.

The classpath extension is in play and would seem to bring the effect of the license closer to that of the LGPL but still. I know a lot of developers, not to mention business people, that dislike the GPL intensely. I would have paid to lurk on Sun’s internal mailing lists while this was being discussed. I can only imagine the number of threads terminated by Godwin’s Law.

Speaking of prospective GPL detractors at Sun, is there no irony in the fact that the GPL was created in response to an action by The Father of Java himself, James Gosling?

What led Stallman to the creation of this copyleft license was his experience with James Gosling, creator of NeWs and the Java programming language, and UniPress, over Emacs. While Stallman created the first Emacs in 1975, Gosling wrote the first C-based Emacs (Gosling Emacs) running on Unix in 1982. Gosling [initally] allowed free distribution of the Gosling Emacs source code, which Stallman used in early 1985 in the first version (15.34) of GNU Emacs. Gosling later sold rights to Gosling Emacs to UniPress, and Gosling Emacs became UniPress Emacs. UniPress threatened Stallman to stop distributing the Gosling source code, and Stallman was forced to comply. He later replace these parts with his own code. (Emacs version 16.56). To prevent free code from being proprietarized in this manner in the future, Stallman invented the GPL.

Gosling has come out in support of GPL Java. I have no evidence of Gosling disparaging the GPL in the past but the whole situation had to be a little weird at best and could have been a WWW-III pissing match at worst.

All of this to say that Sun and Gosling, I think, have accomplished a really great thing here. I have a ton of respect for software authors that have the conviction to place their stuff under GPL and I don’t see any reason to make an exception for Sun. That’s coming from someone who is really not a huge Sun fan, and we won’t even get into Gosling. I'm still waiting on Stephen’s Q&A and it would be interesting to see the FSF weigh in on this but as of right now, Sun just earned a big chunk of credibility as far as I'm concerned.

UPDATE: Steve’s Q&A is up and excellent as usual and the whole friggin ceremony was blessed by Stallman himself so I guess the FSF is okay with the deal.

As for Linux and BSD, I think the impact of a Free Java is quite well known at this point. Partially because there are already Java implementations available under Free licenses and partially because it’s been explained over and over for the past five years. Here’s what I wrote almost exactly two years ago:

The main problem with Java not being open source, IMO, is not so much that the source isn’t available/modifiable (which also sucks) but that the package from Sun cannot be freely redistributed. This really hurts taintless GNU/Linux distributions like Fedora and Debian because they cannot provide a Java package with the core distro. If they cannot provide a Java package with the core distro, it is impossible to provide any packages that rely on Java (i.e. “software being created with Java”) as part of the core distro. Until very recently, this meant that writing an app in Java meant that app had no chance of being included with a Free GNU/Linux distribution. The open source software projects created with Java that Mark talks about are at a tremendous disadvantage to projects using C/C++, Perl, Python, Lisp, bash, and any other language with a free compiler that can be packed into a standard distribution.

There are obviously a bunch of philosophical problems addressed by going GPL but from a practical standpoint I still believe that the packaging issue is the big win for Java.

So all and all I suppose Java is no longer Free but Shackled but now Shackled but Free. I wonder what Tim’s second order of business might be?

The GPL is a, no doubt, huge and admirable step in the right direction for Sun and Java but from a development perspective, my position remains largely the same: We already have a VM.

Get Started

Posted almost 8 years back at The Hobo Blog

Hobo is beta software - version 0.8.3 Although Hobo is in active use in production applications, please be aware that if you choose to deploy a Hobo/Rails application on the Internet you do so at your own risk.

Also note that at this stage we reserve the right to make breaking changes to the API.

Getting Hobo

Hobo is distributed under the terms of the MIT license.

PLEASE NOTE Hobo currently requires Rails 2.1

It’s a good idea to have a quick read of the status page before downloading.

You can find the Hobo Manual on the Docs Page.

Hobo is distributed in two forms, a gem and a plugin (svn repo).

Hobo Gem

The gem is ideal for trying out Hobo with a new app. It gives you a single command:

$ hobo <app-name>

It works just like the rails command, creating a blank Rails application pre-configured for Hobo.

To install, simply

    $ gem install hobo

Hobo plugin

If you want to add Hobo to an existing application, first do:

$ ./script/plugin install svn://hobocentral.net/hobo/trunk
$ ./script/generate hobo --add-routes

(the flag tells tells the generator to modify your config/routes.rb)

Then there are a few optional steps, depending on which Hobo features you’re after. In the screencast you’ve seen:

Hobo Rapid and the default theme:

$ ./script/generate hobo_rapid --import-tags

(the flag tells the generator to add some necessary tags to your application.dryml)

Hobo’s user model:

$ ./script/generate hobo_user_model user
$ ./script/generate hobo_front_controller front --add-routes --delete-index

(the flags tell the generator to add some new routes to config/routes.rb and to delete public/index.html so the front page will work)

Learning Hobo

Please now head over to the documentation page!

Get Started

Posted almost 8 years back at The Hobo Blog

Hobo is beta software - version 0.8.3 Although Hobo is in active use in production applications, please be aware that if you choose to deploy a Hobo/Rails application on the Internet you do so at your own risk.

Also note that at this stage we reserve the right to make breaking changes to the API.

Getting Hobo

Hobo is distributed under the terms of the MIT license.

PLEASE NOTE Hobo currently requires Rails 2.1

It’s a good idea to have a quick read of the status page before downloading.

You can find the Hobo Manual on the Docs Page.

Hobo is distributed in two forms, a gem and a plugin (svn repo).

Hobo Gem

The gem is ideal for trying out Hobo with a new app. It gives you a single command:

$ hobo <app-name>

It works just like the rails command, creating a blank Rails application pre-configured for Hobo.

To install, simply

    $ gem install hobo

Hobo plugin

If you want to add Hobo to an existing application, first do:

$ ./script/plugin install svn://hobocentral.net/hobo/trunk
$ ./script/generate hobo --add-routes

(the flag tells tells the generator to modify your config/routes.rb)

Then there are a few optional steps, depending on which Hobo features you’re after. In the screencast you’ve seen:

Hobo Rapid and the default theme:

$ ./script/generate hobo_rapid --import-tags

(the flag tells the generator to add some necessary tags to your application.dryml)

Hobo’s user model:

$ ./script/generate hobo_user_model user
$ ./script/generate hobo_front_controller front --add-routes --delete-index

(the flags tell the generator to add some new routes to config/routes.rb and to delete public/index.html so the front page will work)

Learning Hobo

Please now head over to the documentation page!