开发者

Specifying class name instead of id in Ajax on Rails

开发者 https://www.devze.com 2022-12-22 08:39 出处:网络
I need to know, how to fetch class name from div instead of id when using Ajax on Rails my coding is like below,

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


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


page << "$$('div.test').first.replace('<button>Thanks</button>')"
0

精彩评论

暂无评论...
验证码 换一张
取 消