Matt RaibleMatt Raible is a Web Developer and Java Champion. Connect with him on LinkedIn.

The Angular Mini-Book The Angular Mini-Book is a guide to getting started with Angular. You'll learn how to develop a bare-bones application, test it, and deploy it. Then you'll move on to adding Bootstrap, Angular Material, continuous integration, and authentication.

Spring Boot is a popular framework for building REST APIs. You'll learn how to integrate Angular with Spring Boot and use security best practices like HTTPS and a content security policy.

For book updates, follow @angular_book on Twitter.

The JHipster Mini-Book The JHipster Mini-Book is a guide to getting started with hip technologies today: Angular, Bootstrap, and Spring Boot. All of these frameworks are wrapped up in an easy-to-use project called JHipster.

This book shows you how to build an app with JHipster, and guides you through the plethora of tools, techniques and options you can use. Furthermore, it explains the UI and API building blocks so you understand the underpinnings of your great application.

For book updates, follow @jhipster-book on Twitter.

10+ YEARS


Over 10 years ago, I wrote my first blog post. Since then, I've authored books, had kids, traveled the world, found Trish and blogged about it all.
You searched this site for "appfuse". 771 entries found.

You can also try this same search on Google.

Using CruiseControl with Subversion

This morning, I had the pleasure of setting up an AppFuse-based project to run under CruiseControl. Normally, this is very easy to do because I have the CruiseControl setup files and instructions. However, this project uses Subversion instead of CVS. Luckily, Subversion is easy to use and I was able to modify things to work quite easily. Below are the steps you can take to modify your AppFuse project to run under CruiseControl and Subversion.

  • Download svant and extract it to your work directory.
  • In build.xml, change your "cvs" target to "svn" and change the tasks appropriately.

        <path id="svn.classpath">
            <fileset dir="svnant-1.0.0-rc1/lib" includes="*.jar"/>
        </path>
            
        <taskdef resource="svntask.properties" classpathref="svn.classpath"/>
        
        <target name="svn">
            <delete dir="checkout/appfuse"/>
            <svn>
                <checkout url="https://svn.java.net/svn/appfuse/trunk" 
                    revision="HEAD" destPath="checkout/appfuse" />
            </svn>
        </target>
    
  • Modify the "test" target in build.xml to depend on "svn".
  • In config.xml, change the <modificationset> to be <svn LocalWorkingCopy="/home/cc/work/checkout/appfuse"/> instead of the <cvs> equivalent.

The instructions have been documented on the wiki and checked into AppFuse's CVS.

Posted in Java at Aug 24 2005, 10:24:26 AM MDT 4 Comments

What do you want to see at Java in Action?

I'm presenting two sessions at Java in Action in October. The first one is a 3-hour tutorial on Comparing Java Web Frameworks, while the second is about Developing Next Generation Web Applications with Ajax in Spring. I'm in the process of writing both of these, and I'm interested to see what Java developers would like to see in these talks.

The tutorial is probably the toughest one because my normal presentation usually only takes about an hour to deliver. For a similar presentation, see Craig McClanahan's The Evolution of Web Application Architectures. I could talk about the history like Craig does, or I could talk about the different frameworks and their features like I usually do. However, I want something more interactive and fun for attendees. I was thinking of live-coding for 20 minutes with each framework, and showing the differences, but that's not a whole lot of fun either. Maybe I could divide the class into 5 groups, educate each of them on features of the framework, and then we could have some sort of debate? Showing code is always something that developers are interested in, so I'll have to figure out how to work that in as well. If you're planning on attending this tutorial - I'd love to hear suggestions.

I'm also curious on what you'd like to see in the 2nd presentation? I was planning on using Equinox (or possibly AppFuse), to show how to use DWR, Prototype and script.aculo.us. A couple of examples I'm thinking of showing are in-page updates and sortable/pageable tables. Any other cool effects or tricks you'd like to see?

Sorry for the cross-post from JRoller, but I wanted to reach the largest possible audience. Please leave comments on the JRoller entry.

Posted in Java at Aug 22 2005, 10:23:34 PM MDT

Prettying up JSPWiki's URLs

Recently, AppFuse user Charlse Li sent me an e-mail with a "PostfixURLConstructor" class designed to pretty up JSPWiki's URL. With the patch he sent, I was able to change URLs from /wiki/Wiki.jsp?page=AppFuse to /wiki/AppFuse.html. Applying the patch was quite easy, but maintaining backwards compatibility and security required a little more work. Below are the steps I went through to get everything working properly:

  • Download postfixurlconstructor.zip and extract to your hard-drive. Copy the "com" directory to your wiki/WEB-INF/classes directory.
  • Change the <url-pattern> of the WikiServlet in web.xml from /wiki/* to *.html.
  • Add the following two lines to your WEB-INF/jspwiki.properties file:

    jspwiki.urlConstructor = PostfixURLConstructor
    jspwiki.PostfixURLConstructor.postfix = .html

This is all you need to do to change the default URL schema. However, if you're like me and you've had a JSPWiki instance setup for awhile, you'll need to maintain backwards-compatibility. I wanted to make sure the old URLs mapped to the new ones. In addition, the "edit URL" changed from Edit.jsp?page=PageName to pageName.html?do=Edit. Since web.xml and <security-constraint> can't contain regular expressions, I used the ultra-cool UrlRewriteFilter to solve both issues. Here's the steps I went through to configure it properly:

  • Download UrlRewriteFilter 2.5.1 and extract the JAR to your WEB-INF/lib directory.
  • Change your web.xml to use a 2.3 DTD instead of a 2.2 DTD and add the filter and filter-mapping to web.xml.
  • Create a WEB-INF/urlrewrite.xml file with the following contents:
<?xml version="1.0" encoding="utf-8"?>
<!DOCENGINE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 2.5//EN"
    "http://tuckey.org/res/dtds/urlrewrite2.5.dtd">

<urlrewrite>
    <rule>
        <from>^/Wiki.jsp\?page=(.*)$</from>
        <to type="redirect">$1.html</to>
    </rule>

    <rule>
        <from>^/(.*).html\?do=Edit$</from>
        <to type="redirect">Edit.jsp?page=$1</to>
    </rule>
</urlrewrite>

That's it - restart your server and you should be good to go. Thanks for the patch and instructions Charlse!

Update: There does seem to be a couple of issues. The 1st is that none of the attachments are resolving correctly (example). The 2nd that when I try to edit a page, it always shows up with the Main page's text. I'm not going to back out the change just yet, but I will if I can't fix it in the next several hours.

Update 2: I ended up backing out this change, but left in a forward from *.html to Wiki.jsp?page=$1 so all URLs in this post should still work. The "not being able to edit" was the major reason I rolled back to the old URL schema. The attachment issue seems to be related to my browser's cache. Clearing it fixed the problem.

Posted in Java at Aug 21 2005, 03:01:59 PM MDT 1 Comment

Integrating Lucene with Hibernate

The code_poet has an interesting post on using a Hibernate interceptor to index objects for Lucene searching. I've been thinking about integrating Lucene into AppFuse (or at least providing a tutorial) for quite some time. Hopefully this post will serve as a starting point when I do. I wonder how much the Lucene code can be simplified by the Spring support in the Spring Modules project?

Posted in Java at Aug 17 2005, 10:19:09 PM MDT 17 Comments

Roller 2.0 looks good!

Dave has posted some screenshots of Roller 2.0. I have to say, the new UI is a big improvement, both with colors and fonts. I hope to try 2.0 out today and hopefully get it installed at Virtuas in the next week or two. I can't wait until this release is installed on JRoller - it'll be very cool when many people can participate in a SourceBeat blog. Nice work Dave!

FWIW, I plan on hanging out in #appfuse and #roller on irc.freenode.net this week. Stop by and say hi if you have questions about either project.

Posted in Roller at Aug 16 2005, 09:32:11 AM MDT Add a Comment

Failed upgrade to Struts 1.2.7

Yesterday I made an attempt to upgrade AppFuse to use Struts 1.2.7 instead of 1.2.4. Everything seemed to go smoothly until I started running my Canoo WebTests with JavaScript enabled. It turns out there's a major bug (IMO) in Struts 1.2.7 where the JavaScript rendered by Commons Validator can't handle the Struts' <form> tag in XHTML mode. I tried a nightly build (20050809), but it's not fixed there either, so I backed out the upgrade.

The interesting thing about Struts 1.2.7 is SpikeSource has certified this release. Are they not testing JavaScript as part of their certification test?

Another thing I attempted to upgrade yesterday was Canoo WebTest from build574 to build976. No dice - mainly because of issues with Prototype (I think). The worst part is everything works fine in a browser. Even worse is I still have a problem with build574, but it doesn't cause the tests to fail. Times like this make me wish Selenium was more polished and ready to use. I talked with some ThoughtWorkers last week and they said the Java driver is ready for a 1.0 release, but one of the committers wanted to make sure all language drivers were ready first (at least that's what I remember).

Posted in Java at Aug 10 2005, 11:17:35 AM MDT 9 Comments

Things I learned from OSCON

While at OSCON last week, I learned quite a few things. Many of these are my own opinions, so feel free to disagree with them.

Ruby is very cool

The main reason (for me) that Ruby is cool is because it's new. I don't have to know any of its history to know what makes it tick. It's easy to learn and has powerful language features that make it easy to use. I think the primary reason people, particularly Java developers, are excited about it is because it releases them from all the shackles they're accustomed to with Java. I have absolutely no plan to ditching Java and jumping to Ruby, but I do want to learn it so I can use it when it's a better fit than Java.

How to learn Ruby and retain that knowledge is the hard part. My current plan is to buy Programming Ruby and Agile Development with Rails. Unfortunately, I realize that I probably won't be able to finish these b/c I'll get bored and both will likely serve as more of a reference than a knowledge creator. I haven't been able to read a technology book cover-to-cover in several years. I couldn't even finish The Pragmatic Programmer for crying out loud. I realize that the best way to learn is to do, but the best way to do is to get paid to do. To facilitate this, I hope to develop some apps we can use at Virtuas. Of course, I'll try to find good open-source solutions first.

Rails has a lot of great ideas

The interesting thing about Rails is many of its good ideas are from Ruby. The built-in Webbrick web server is part of the language. The only way to come close in the Java world is to embed Jetty or something like that. I'll definitely be looking into embedding Jetty into AppFuse in the near future. The other thing I really like about Rails, and that I've been doing in AppFuse a bit is convention over configuration. As part of AppFuse, I'm already making a lot of decisions for users. The next step seems to be making all decisions for users, but allow them to override. It'd be cool to write some code that sweeps through all classes at startup and auto-configures them, w/o the need for any XML. If nothing else, the XML could be generated using reflection.

The biggest thing I learned from Rails is I need to provide 1) an easier upgrade path and 2) better Ajax support. Because I'm supporting so many different web frameworks, solving #2 might be a bit tricky - but could be done by writing tag libraries or components. Hopefully the framework developers will beat me to it and I won't have to do anything. As far as #1, I'm hoping I can move to a single appfuse.jar that contains all the base classes. Hopefully I can use a little JSP pre-compile action to re-use the existing JSPs for user management/etc. If not, I can always use something like FreeMarker to store the default view files in a JAR.

Creating Passionate Users is all about inspiring emotion

Kathy Sierra's talk about inspiring emotions among your users to make them transparently excited about your product/company was a real eye-opener. I can totally see what she's talking about and I'm happy to say I'm already doing some of it. This blog seems to attract lots of readers, some more passionate than others, just by talking about web technologies and Java. This does translate into more business for Raible Designs, whether it's the title image or URL, it doesn't really matter. Folks do figure out that I have a company and I do work with the technologies I talk about.

To apply these concepts to AppFuse and Virtuas is a little more difficult. For AppFuse, I can probably teach people how to better use Hibernate, Spring and Ajax - and then show how AppFuse can simplify things. Building in easy-to-use Ajax support is probably essential to really get this going. For Virtuas, we could re-vamp our site to provide education about open source and its history - providing users with a way to become open source experts. It would also be cool to do real-time reporting of how we helped a company adopt open-source.

Ideas, ideas, I have lots of ideas after last week.

Posted in Java at Aug 08 2005, 03:40:38 PM MDT 4 Comments

[OSCON] Spring MVC vs. WebWork Smackdown

Matthew Porter and I's Spring MVC vs. WebWork Smackdown presentation was a lot of fun this morning. We had a boxing bell (that I got off eBay) and had a good time ragging on the two frameworks. The only surprise was that Matthew actually ran some metrics on the Spring MVC vs. WebWork code in AppFuse and pointed out that the WebWork version required 25% less code than the Spring version. Oh well. The hard part about this presentation for me was trying to defend Spring MVC and saying it's better than WebWork. Matthew obviously felt strongly that WebWork was the better framework, whereas I like them both.

Posted in Java at Aug 03 2005, 05:15:43 PM MDT 7 Comments

[OSCON] Wednesday Morning

I got a good night's sleep last night so I'd be fresh and ready for the Smackdown today. Matthew Porter, Scott Delap and I visited Jive Software's offices last night and had a great time sipping suds in their beautiful downtown office.

My AppFuse tutorial yesterday was well-received by a packed room of developers. Rather than writing code the whole time and doing a measly 30-slides, I added a bit more meat about Spring, Hibernate and testing. Most of audience was unfamiliar with Spring, so this seemed like the right thing to do. Of course, this led to more talking and less coding, but most of the folks I talked to were nevertheless very happy with the tutorial. If you'd like, you can download my presentation from the event.

Thanks to Rob Harrop and Thomas Risberg for both letting me know about the lack of Spring experience, as well as sitting in on my session. It was pretty cool having these guys in the room, as well as SiteMesh/jMock inventor Joe Walnes. Without these guys, many of the cool features in AppFuse would not be possible.

Now I'm sitting in the beginning Keynote session at OSCON, where they've announced they have a record 2000 attendees this year. In addition, it looks like OSCON is in Portland for the long run - this is the 3rd year it's been in Portland. Rather than moving to a new city like they used to, they've decided to stay b/c conference attendees like it so much.

The "unofficial" tagline of the conference is fun. Open source is fun and exciting - both to develop and use. This is in stark contrast to closed source software that tries to stay stable and boring, with no surprises.

When O'Reilly's CodeZoo launched, it only listed Java open source projects. As of today, they've added python.codezoo.com and ruby.codezoo.com, in addition to java.codezoo.com.

Tim O'Reilly

O'Reilly is not just book publisher or conference producer - but also a company that looks to the future and tries to figure out what's next. To highlight this vision, they've created O'Reilly Radar.

We're currently going through "The Open Source Paradigm Shift". Integration of commodity components has led to a new model where value gets captured. Rather than being at the software level, it's at the services level.

Key Questions for Open Source Advocates

  • Will "web 2.0" be an open system? What do "open services" look like?
  • Data as the "Intel Inside" - will we end up needing a Free Data Foundation in 2010?
  • How does the paradigm shift change our business models and development practices?
  • Who shoujld we be watching and learning from?

Things on O'Reilly's Radar

  • Ruby on Rails: new platform and new language. May well be the Perl of Web 2.0.
  • GreaseMonkey: a Firefox extension that alters websites to fit your view. A website is traditionally closed. GreaseMonkey "opens up" a website and rewrites it for the user.
  • HousingMaps.com: leveraging Google Maps and existing data from a bunch of different webservices to build a better website.
  • Ajax: html, javascript and css. The "css" tag on del.icio.us has gone down as the "ajax" tag has gone up.
  • Findory: Uses the articles you like in blogs and news, and finds similar articles. Similar to Amazon's recommendation system.
  • Internet Telephony: Asterisk in particular. Skype and Broadvoice. Broadvoice is pushing BYOD (Bring Your Own Device).
  • HomeBrew: similar to Tivo.
  • Firefox
  • Opening up hardware, not just software - i.e. Car PC Hacks, Smart Home Hacks.

For more, go to the Visualizing Technology Trends on Thursday afternoon. For the first time, the computer book market has stabilized. This is a good sign that the computer industry is about to start rebounding. As far as the book market goes, it's market share and growth - Java still leads the pack by a pretty wide margin. A large reason of this is due to Open Source Java. SimplyHired.com spiders 7.9M jobs on 755 different job boards. General books on Linux are up, especially non-RedHat distros. Books on RedHat have decreased significantly.

This is an interesting conference to be at when you're a Java developer. For the most part, everyone seems to be Perl fans, followed by Python, and a few Ruby guys. Most of these developers are very vocal about the fact that they don't like Java. Then again, Java is the leader in many areas - and it's the open source way to hate the guy on top.

Kim Polese, SpikeSource

Building on the Architecture of Participation. A transformation from Do It Yourself (DIY) to Do It Together (DIT). Thanks to the architecture of participation, open source has achieved World Domination - as evident by governments mandating it and IBM pouring billions into it.

The architecture is characterized by:

  • Commoditization of software
  • Network-enabled collaboration
  • Software customizability

In Phase I, we built and we built with. Open source had DIY origins. Now we're in Phase II, where increasingly the action is out in the long tail. Countless new building materials are piling up on the long tail. Now it's possible to build just about anything with anything. IT shops are building a phenomenal set of DIY "packages" that combine components from both ends of the curve.

The two problems with this:

  • Velocity mismatch: all components are on different release schedules. Linux, Apache, MySQL - all on a different release schedule. In addition, the ones on the other side (Lucene, Struts, Mambo) are on a different cycle.
  • Dependencies: When one version of one product changes - what happens to all the dependencies?

To solve these problems, companies are developing formalized proceses like review boards, support centers, OSS incubation centers, testing groups and they're certifiying / defining stacks internally. Most of this work is laborius and not related to the core competency of the business.

What's next? Phase III - IT becomes core. They do this by offloading critical but non-strategic work to independent service companies. DIY evolves into DIT with the help of independent service companies. Of course, this is all leading up to the fact that SpikeSource provides these services. It's funny that as soon as Kim said "SpikeSource" - all the presentation screens in the room quit working (not on purpose). A minute later they're back. This goes to show that marketing is not liked by the Open Source Gods. ;-)

"Testing is the single biggest refactoring shift in sofware." - J.P. Rangaswami, CIO, DrKW.

We need testing on a massive skale. For this reason, Murugan Pal and Ray Lane started SpikeSource. They saw the next phase is testing open source software so we can scale testing, together. Solve velocity mismatch and dependency problems with rapid per-defect patch management and dynamic stack configuration.

Testing has always been the software's ugly stepchild. We need to scale open source testing the way we scaled open source development. Some perspective: Microsoft has a 1:1 ratio of developers to QA Engineers. There's no Microsoft for open source software, nor should there be. To solve testing on a massive scale, you need participation plus automation. For models of how both scale, think eBay, Google and Amazon. Their best assets were their customers that supplied data that made their services more useful.

Testing is just one service among many. The Linux distros and middleware core building blocks have been there for awhile. Now we have applications and service companies as well. Who benefits when we have abundant integrated, tested, validated automatically patched stacks? IT and ISVs shift high-value development resources to customer-faces - differentiating features and services. In addition, many other groups benefit and higher quality software gets developed.

Testing will do for open source what it did for chip design a generation earlier. Testing is what catapulted the chip industry forward in the 80s. The new testing tools moved VLSI foward. Countless new IC-powered products were made possible and at much faster development speeds. Solving the testing problem can't be done by one company alone. "Come Test with Us..."

After Kim, another speaker (Andrew from OSDL) began his talk. He talked in a monotone and lacked a presentation. The room quickly began to leak people, me being one of them.

Posted in Open Source at Aug 03 2005, 11:15:08 AM MDT 4 Comments

[OSCON] Monday Afternoon

Ruby on Rails - Enjoying the ride of programming
Presented by David Heinemeier Hansson, OSCON 2005

About David: started doing Ruby in June 2003. Involuntary programmer of need, served 5 years in PHP. Spent 7 months in a Java shop.

Prerequisites of play: Ruby 1.8.2, dated December 25th. A database, pick one of 6. The RubyGems miner. Some gems called Active and Action.

Directory structure that Rails creates is more for convenience than anything. By picking conventions for you, it makes things easier. It might feel like flexibility is being ripped away from you - but you can change the defaults. However, by following the default settings, things will just work and life will be much easier for you as a developer.

I did a bit of playing on my PowerBook while listening to David's talk. I have Tiger installed, but found that Ruby 1.8.1 was installed on my machine (in /sw/bin/) thanks to Fink. My running "rm -r /sw/bin/ruby" and restarting iTerm, the default changed to /usr/bin/ruby, which is 1.8.2. From there, I downloaded and installed the Rails Installer.

I hate to admit it, but this talk is pretty boring so far. Probably because I've read David's blog for the past 6 months and watched most of the Rails videos. I haven't really learned a whole lot in the first 45 minutes of this talk. To be fair, the content of the talk seems to be properly targeted - there's been a fair amount of questions and everyone seems to be interested. Almost all of the seats are filled in the room; 3-4x as many folks as Dave Thomas's Ruby talk.

One interesting thing I've learned today is many features of Rails (i.e. Webrick) are actually a part of Ruby, not Rails. In addition, Ruby seems to have frequent releases and more features are added to the language each time. I guess that's the advantage of having a language that's not developed by committee.

When creating model objects in Rails, the default is to use a plural form of the object for the database table name. For example, a comment model will map to a comments table. Dave Thomas did mention in this morning's session that Rails isn't smart enough to figure out "sheep" - it gets maps to "sheeps". Apparently, you can easily override this behavior by specifying use_plurals=false somewhere. Another convention built-in to the framework is that the primary key is named "id" and its an auto-incrementing field.

"The database is a data bucket. I don't want any logic in my database, I want it all to be in my data model."

Rails doesn't handle composite primary keys. Rails is mostly designed for green-field development, where you get to control your database and its schema.

There are a number of key properties you can use in your database tables (a.k.a. your model objects) that will automatically get updated if you name them properly. Their names are created_at (datetime), created_on (date), updated_at and updated_on. There are also a number of time-related helpers, i.e. distance_of_time_in_words_to_now(date) » less than a minute ago.

Rails also has the concept of filters, which you can apply to a group of controllers. To use a filter, you define the filter method in controllers/application.rb and then you have to add a before_filter clause in each controller you want it to be applied. While it's cool that Rails has filters, it would be nice if you didn't have to configure the controllers that filters are applied to in the controller. To me, it seems more appropriate to be able to configure the where the filters are applied externally to the controllers. It seems more natural to me that you'd put something like apply_to_controller => { :controller1, :controller2 } in application.rb.

For doing page decoration with Rails (i.e. SiteMesh), you simply create a decorator in views/layouts. If you want a particular decorator to apply to a particular controller, you just name the file the same as the controller's URL. For example, if you have a posts controller (really a PostController.rb file), you'll create a decorator named posts.rhtml to decorate all the HTML rendered from the PostController - regardless of whether you're rendering from a method or from a view template. To have a decorator apply to all controllers, you can simply create a file named view/layouts/application.rhtml. This seems like something that SiteMesh could easily do as well - for example defaulting to /decorators/default.jsp (or something similar).

One thing I like about Rails is it's flash concept and how easy it makes it to display success messages. In my experience with Java web frameworks - many make this more difficult than it should be.

Testing Rails Applications

When running tests, Rails automates the creation of a test database instance that mirrors the schema of your development database. One slick thing in a Rails project's Rakefile is that you can run all the tests that you've touched in the last 10 minutes. I think one of the most unique thing about Rails/Ruby vs. Java is all that almost all of the files (Rakefile, code generation scripts, etc.) are written in Ruby.

Controller tests have a "mini-language" for simulating a browser when testing controllers. For example:

def test_login 
  get :login
  assert_response :success<
  assert_template "login" 
  
  post :login, :password => "secret!"
  assert_response :success
  assert !session[:authorized]
  
  post :login, :password => "secret"
  assert_response :redirect
  assert session[:authorized]
end

In the Controller tests, you can set cookies, parameters and mimic almost everything the browser can do. You can also test that your model objects have been manipulated appropriately. For example:

def test_create_post 
  post :create, :post => { :title => "This is my title", :body => "1" }
  assert_response :redirect
  assert_kind_of Post, Post.find_by_title("This is my title")
  
  post :create, :post => { :title => "", :body => "1" }
  assert_response :success # something was rendered, regardless of error messages
  assert_equal "don't leave me out", assigns(:post).errors.on(:title)
  #or assert_equal 1, assigns(:post).errors.count
end

The find_by_title method is a dynamic finder, where ActiveRecord creates find_by methods for each attribute of the model object. Another cool feature of testing is you can add a line with "breakpoint" in it - and the test will stop executing there - giving you access to all the variables at that point.

Ajax

The main reason for integrating JavaScript into Rails is so developers don't have to write JavaScript. For most developers, writing JavaScript is a pain because of browser incompatibilities and such. Rails ships with 4 JavaScript libraries, including Prototype and Script.aculo.us. It's easy to include the default JavaScript libraries in Rails:

<%= javascript_include_tag :defaults %> 

Both the link_to and form_tag methods have a "remote" equivalent (i.e. link_to_remote) that allows you to hook into Ajax, and by defining a :complete callback, you can call fade effects and the like. You can override many of the lifecycle stages of Ajax, but the most common is the :complete callback. In a Controller, it's easy to distinguish Ajax calls from non-Ajax calls using:

if request.xml_http_request?
  # do logic, for example rendering partials
end

Partials seem to be a pretty cool feature in Rails. They're actually just parts of a page that you include in a parent page with render :partial => "viewName". The slick thing about partials is you can actually populate their model and return them in a controller after an Ajax call.

The Ajax demos that David just showed are pretty cool. He was able to easily show how to delete a comment in his "weblog app", as well as add a new comment - w/o refreshing the page. The slick part of the add was he was easily able to add the new comment id to the Ajax response header, and then grab it in a callback and use the id to reference a <div> and use the yellow fade technique to highlight and fade the new comment.

That's the end of Dave's talk, and the first day at OSCON. Thanks to Dave and David for showing me the cool features of Ruby and Rails.

Posted in Open Source at Aug 01 2005, 05:02:31 PM MDT 5 Comments