Hide parent element

I have some code that calls a partial to display one or more blocks
within a div tag. I want to have a close button (or cancel link) that
will fade that block but leave the others. Here is the code:

LINK:
<%= link_to_remote “Add Miscellaneous Link”, :url => { :action =>
:add_iyc_link } %>

add_iyc_link.rjs:
page.insert_html :bottom, ‘links’, :partial => ‘add_iyc_link’
page.visual_effect :highlight, ‘links’

_add_iyc_link.rhtml:

<%= image_tag "cancel.png", :class => 'close', :onclick => "new Effect.Fade('iyclink', {duration: 3})" %> Title
<%= text_field 'in_your_classroom_link', 'title[]', :size => '30', :class => 'link' %>
URL
<%= text_field 'in_your_classroom_link', 'url[]', :size => '50', :class => 'link' %>
Description [Markdown]
<%= text_area 'in_your_classroom_link', 'bodytext[]', :cols => '70', :rows => '5' %>

Can this be done? The problem is when I have two or more blocks and
click the cancel button the first gets faded which is not the one I
want.

The problem is that each of your

elements all have the same id. The
javascript works with the id of elements in the DOM to do it’s thing.
When
it tries to do it’s thing it finds the first element with the id
specified.

You need to specify each with a unique id.

One way would be to include a random string generation function in a
helper. eg

def random_id
chars = (“A”…“Z”) + (“a”…“z”) + (“0”…“9”)
(1…10).inject(String.new) { |str, i| str << chars[rand(chars.length)] }
end

then in your partial
<% rand_id = random_id %>

other stuff in here

I think this should work unless you need the id to relate to the actual
record in the db

The weird thing is when I put <% rand_id = random_id %> in my partial
the rjs won’t display my partial. I can take it out and it works fine.

Daniel ----- wrote:

The problem is that each of your

elements all have the same id. The
javascript works with the id of elements in the DOM to do it’s thing.
When
it tries to do it’s thing it finds the first element with the id
specified.

You need to specify each with a unique id.

One way would be to include a random string generation function in a
helper. eg

def random_id
chars = (“A”…“Z”) + (“a”…“z”) + (“0”…“9”)
(1…10).inject(String.new) { |str, i| str << chars[rand(chars.length)] }
end

then in your partial
<% rand_id = random_id %>

other stuff in here

I think this should work unless you need the id to relate to the actual
record in the db

Seth,

My bad… the chars line should read

chars = (“A”…“Z”).to_a + (“a”…“z”).to_a + (“0”…“9”).to_a

or something similar

Thanks Daniel. That worked.

Seth

Daniel ----- wrote:

Seth,

My bad… the chars line should read

chars = (“A”…“Z”).to_a + (“a”…“z”).to_a + (“0”…“9”).to_a

or something similar