• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

make Dynamic ID available to js.erb

 
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a sample App.The view is:


To correspond to this, I have increment.js.erb with the following:



Now, when button is clisked, I want to replace the related number and the +1 button with some message like "Incremented".
The problem here is, using static IDs doesn't work for very obvious reason.And the same goes for class.
One very good idea is to generate dynamic IDs, e.g.,
But, how to make this dynamic ID available to the js.erb?
 
Sheriff
Posts: 1367
18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The controller knows about the dynamic number, right? Could it assign that to the template?



 
santoshkumar savadatti
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It doesn't work.
There's a gem available for this purpose called jsvars.
I'll try it.
 
santoshkumar savadatti
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It doesn't work.
There's a gem available for this purpose called jsvars.
I'll try it.


Your suggestion worked fine Katrina.I had made some mistakes.Now i did this:
in the view, i had to say
Then in the controller,
And in the js.erb,

That was all needed.
Thanks.
 
Katrina Owen
Sheriff
Posts: 1367
18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Glad it helped!
 
reply
    Bookmark Topic Watch Topic
  • New Topic