how to add a dynamic value for a tag's id attribute

2 views
Skip to first unread message

Guo Yangguang

unread,
Apr 13, 2008, 9:26:31 PM4/13/08
to rubyonra...@googlegroups.com
how to add a dynamic value for a tag's id attribute in the ajax
call.For example:several "<td id="#{product.id}" colspan="4"
align="center"></td>" and
"<td><%=link_to_remote("MoreInfo",:update=>"#{product.id}",:url=>{:action=>"more_info",:id=>product},:method=>:get)-%></td>"in
a page,i want every ajax result to replace its own "<td
id="#{product.id}" colspan="4" align="center"></td>",instead of the same
one.
so how to add a dynamic value for a tag's id attribute
--
Posted via http://www.ruby-forum.com/.

Phlip

unread,
Apr 14, 2008, 12:57:04 AM4/14/08
to rubyonra...@googlegroups.com
Guo Yangguang wrote:

> how to add a dynamic value for a tag's id attribute in the ajax
> call.For example:several "<td id="#{product.id}" colspan="4"

Just a note that's an illegal ID. In summary, an HTML ID attribute must be
unique to its page, and must satisfy naming conventions commonly ascribed to
language variables, such as JavaScript variables. An ID may not contain
punctuation or start with a number.

Always go id="product_<%= product.id %>", and also think about making the
product_ prefix more context-specific.

> align="center"></td>" and
> "<td><%=link_to_remote("MoreInfo",:update=>"#{product.id}",
>:url=>{:action=>"more_info",:id=>product},:method=>:get)-%></td>"in

:id => product.id

You might be passing the whole product by copy there. I'm not sure what it will
turn into!

> a page,i want every ajax result to replace its own "<td
> id="#{product.id}" colspan="4" align="center"></td>",instead of the same
> one.

Put the useful prefix on the id.

Next, think about handling the Ajax call with render :update do ... and put
inside that an update_html directed at that id.

--
Phlip

Guo Yangguang

unread,
Apr 14, 2008, 6:01:08 AM4/14/08
to rubyonra...@googlegroups.com
Thank you Phlip.But i also want to ask you how to make an ajax call to
bring out an some size window when click a link.Just tell me the outline
instead of detail about how to.Thank you!
Reply all
Reply to author
Forward
0 new messages