views:

44

answers:

2

Hi friends,

I need to know, how to fetch class name from div instead of id when using Ajax on Rails

my coding is like below,

<div id="test_test1" class="test">
</div>

<div id="test_test2" class = "test">
</div>

and on Controller,

page.replace_html "test_test1", "<button>Thanks</button>"

please help me to solve this problem.

Thanks

+1  A: 
page << "$$('div.test').first.replace('<button>Thanks</button>')"
clyfe
Thanks friend for ur post
Senthil Kumar Bhaskaran
+1  A: 

If you want replace values of all divs with class 'test' you can use from rjs this code

page.select('.test').each do |value|  
  value.update 'new value' 
end

If only one of them - then you shouldn't do it from rjs because of class of dom element not unique. You can use link_to_remote callbacks. See docs here - http://api.rubyonrails.org/classes/ActionView/Helpers/PrototypeHelper.html#M001645

uzzz
Thanks for the post
Senthil Kumar Bhaskaran