RJS, select, & replace_html

15 views
Skip to first unread message

Will Clark

unread,
Nov 12, 2009, 4:39:15 PM11/12/09
to rubyonra...@googlegroups.com
I need to update a series of html tags with the same content.

I've tried running the following in my rjs file:

page.select(".some_class").each do |item|
item.replace_html("Some Content")
end

But it won't work.

However, when I run:

page.select(".some_class").each do |item|
item.hide
end

it does.

I know part of the problem is that replace_html needs the element id.
But how, in RJS, would I do that?

Thanks
Will
--
Posted via http://www.ruby-forum.com/.

Frederick Cheung

unread,
Nov 12, 2009, 5:19:43 PM11/12/09
to Ruby on Rails: Talk


On Nov 12, 9:39 pm, Will Clark <rails-mailing-l...@andreas-s.net>
wrote:
> I need to update a series of html tags with the same content.
>
> I've tried running the following in my rjs file:
>
> page.select(".some_class").each do |item|
>   item.replace_html("Some Content")
> end
>
> But it won't work.
>
> However, when I run:
>
> page.select(".some_class").each do |item|
>   item.hide
> end
>
> it does.
>
> I know part of the problem is that replace_html needs the element id.
> But how, in RJS, would I do that?

something like page.replace_html item, 'some_content' might work
(insude the each block)
However when you get to the point that you're fighting rjs you might
as well just write the raw javascript

Fred


>
> Thanks
> Will
> --
> Posted viahttp://www.ruby-forum.com/.

Will Clark

unread,
Nov 12, 2009, 5:41:11 PM11/12/09
to rubyonra...@googlegroups.com
Fred, that worked, I was just about to write my own method to handle it
too.

Thanks!

- Will

Reply all
Reply to author
Forward
0 new messages