• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help convert rails 2 snippet to rails 3

 
santoshkumar savadatti
Ranch Hand
Posts: 95
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 1367
18
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 95
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic