aspose file tools*
The moose likes Ruby and the fly likes Help convert rails 2 snippet to rails 3 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Languages » Ruby
Bookmark "Help convert rails 2 snippet to rails 3" Watch "Help convert rails 2 snippet to rails 3" New topic
Author

Help convert rails 2 snippet to rails 3

santoshkumar savadatti
Ranch Hand

Joined: Apr 27, 2010
Posts: 95
I found an article here.
But the problem is, it's Rails 2 code.
My interest is in the following snippet:


I changed it to this:


But instead of replacing the content of the div, its reloading the whole page.
What should be modified to make it work in rails 3?
Katrina Owen
Sheriff

Joined: Nov 03, 2006
Posts: 1364
    
  17
If you look at how link_to is defined in Rails 3 you'll see that you basically have three arguments to the method (the last is optional).

1. the anchor text or body of the link
2. the href, however you decide to build it or reference it
3. the html options

In your example I think you've mixed the html options up with the url options:


1. 'Click'
2. {:action => 'say_when'}
3. {:remote => true, :update => '#time_div'}

It's been a very long time since I've done anything with prototype, so I'm not sure about the helpers there, but this is the basic idea.

The confusing thing is that if you can drop a bunch of braces and still have the code run correctly.

It might be clearer if you use a named route for the second part, and add braces to the html options:


For more detail about the link_to helper take a look at the documentation here:
http://apidock.com/rails/ActionView/Helpers/UrlHelper/link_to
santoshkumar savadatti
Ranch Hand

Joined: Apr 27, 2010
Posts: 95
I got it working using UJS.
In the view, i have:


The controller is as follows:


To display this, i created "say_when.js.erb" which has the following lines:


And the Resulting App works just as described in the site.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Help convert rails 2 snippet to rails 3