Episode 74: Complex Forms Part 2

Posted about 1 year back at Railscasts

See how to use Javascript and RJS to add and remove form fields dynamically. This episode will build upon the previous episode allowing you to create any number of tasks in one form the same time a project is created.

Episode 74: Complex Forms Part 2

Posted about 1 year back at Railscasts

See how to use Javascript and RJS to add and remove form fields dynamically. This episode will build upon the previous episode allowing you to create any number of tasks in one form the same time a project is created.

Rails 2.0: taking the plunge

Posted about 1 year back at No Strings Attached

With the Rails 2.0 “preview release” out and all the buzz, you might be thinking of checking out what is it all about. These notes will help you with switching your existing application to use the latest version of this fantastic framework.

Before proceeding to the installation, run unit tests against your application. Take a note of if they all passed and, if you were less fortunate, which tests fail. You will compare these results with the ones after the switch.

Installation

If your application is using Rails 1.2.3, you’re probably set up to use Rails gems. You’ll find out that you can easily install the “preview release” gem by specifying explicit source after the gem install command.

gem install rails --source http://gems.rubyonrails.org

This isn’t the only way of updating, however. You can freeze a particular application to 2.0 PR by using the rails:freeze:edge built-in Rake task.

rake rails:freeze:edge TAG=rel_2-0-0_PR

This will copy the whole framework to vendor/rails. There is a caveat with this approach if you’re switching from Rails 1.2.3. A new framework called Active Resource has been added to the Rails bundle, which older Rails releases know nothing about. So, in the first run, Rails will export all components except ActiveResource, which it will later search for and fail miserably with these (misleading) messages:

warning: already initialized constant OPTIONS
undefined method `options' for []:Array (NoMethodError)
... [confusing stack trace] ...

This happens when you try to start Mongrel after freezing your app to 2.0 PR. A simple solution is to repeat the rake rails:freeze:edge ... command; ActiveResource will get downloaded then. Other solution might be to first upgrade to Rails 1.2.4 or higher.

The third solution might be for all you adventurous ones (and me): checking out the actual trunk to a single location on your computer.

svn co http://svn.rubyonrails.org/rails/trunk ~/projects/rails/edge

Now you have a working copy of edge Rails that you can update with Subversion at your convenience. Next, go to your application and symlink that fresh checkout from vendor/rails (this obviously doesn’t work on Windows):

ln -Tvsf ~/projects/rails/edge vendor/rails

Your application is now bound to Rails trunk at you can keep “riding the Edge” until 2.0 final release. It only takes this:

svn up vendor/rails/

What can be harder than that?

So now what?

Now, your application is switched to Rails 2.0 and there is a big chance that it is probably broken all over the place. First, check if your tests still pass:

rake test

If they pass, great. If they don’t, don’t sweat (yet). You’ll probably figure out what it is in a minute. In fact, I’ve built an awesome Ruby script that can help you finding what changed in Rails 2.0 that you might have missed. Tips on how to run the script on your project are in the comments at the top; check it out. Here is some sample output:

Your application doesn't seem ready to upgrade to Rails 2.0. Please take a
moment to review the following:

-- old render methods ----------------------------------------------------------

  The old `render_{something}` API has been removed.  (changeset 7403)

  Change `render_action` to `render :action`, `render_text` to `render :text`
  (and so on) in your controllers.

  files:
  app/controllers/admin/export_controller.rb:4:  render_text "hello world"

-- acts_as_tree ----------------------------------------------------------------

  acts_as_tree has been extracted from Rails core.  (changeset 7454)

    script/plugin install acts_as_tree

  files:
  app/models/page.rb:11:  acts_as_tree :order => 'virtual DESC, title ASC'

Other gotchas I have come across:

  1. Rick Olson’s widely popular restful_authentication generator has generated a call to redirect_to_url in lib/authenticated_system.rb. You will not be able to log in until you change redirect_to_url to redirect_to, since the former was deprecated and is now removed.
  2. Using Haml and your templates suddenly render as plain Haml source? You probably have Globalize or Simple Localization plugin installed. They hack into Rails ActionView in a way that is incompatible with Rails 2.0. Find a list of extensions in plugin sources that looks like this: /.(rjs|rhtml|rxml|erb)$/. Then add haml to that list and restart the server. Alternative: update the plugin you’re using; its authors might have fixed the issue already.

You’re done. Don’t forget to check out Rails 2.0 release notes again. Happy developing ;)

Episode 45: RJS Tips

Posted about 1 year back at Railscasts

This episode is packed with little RJS goodies. Learn the different ways to access an element, how to add "if" conditions and how to apply an effect to multiple elements.

Episode 45: RJS Tips

Posted about 1 year back at Railscasts

This episode is packed with little RJS goodies. Learn the different ways to access an element, how to add "if" conditions and how to apply an effect to multiple elements.

Episode 44: Debugging RJS

Posted about 1 year back at Railscasts

RJS and AJAX can be difficult to debug. Many times you don't get any error message in the browser. Learn different techniques for solving these tricky problems in this episode.

Episode 44: Debugging RJS

Posted about 1 year back at Railscasts

RJS and AJAX can be difficult to debug. Many times you don't get any error message in the browser. Learn different techniques for solving these tricky problems in this episode.

Episode 43: AJAX with RJS

Posted about 1 year back at Railscasts

This episode will walk you through adding AJAX functionality to a form using RJS. See how to easily update multiple elements on a page.

Episode 43: AJAX with RJS

Posted about 1 year back at Railscasts

This episode will walk you through adding AJAX functionality to a form using RJS. See how to easily update multiple elements on a page.

JQuery Ajax + Rails

Posted about 1 year back at mad.ly

UPDATE Old stuff here! See Errtheblog's post on jQuery for more up-to-date information… *** I've been working on integrating jQuery's Ajax capabilities into a Ruby on Rails application; here's what I've discovered so far: RJS templates (yes, you can use them!) UPDATE see Javascript + embedded Ruby templates with Rails, out-of-the-box for a way to skip using RJS templates altogether [...]


1 ... 3 4 5 6 7 8