Win a copy of Transfer Learning for Natural Language Processing (MEAP) this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • salvin francis
  • Carey Brown
  • Frits Walraven

Help convert rails 2 snippet to rails 3

Ranch Hand
Posts: 95
  • 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?
Posts: 1367
  • 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:
santoshkumar savadatti
Ranch Hand
Posts: 95
  • 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.
You don't know me, but I've been looking all over the world for. Thanks to the help from this tiny ad:
Two software engineers solve most of the world's problems in one K&R sized book
    Bookmark Topic Watch Topic
  • New Topic