# Assiging an attribute in rhtml

**URL:** <https://www.ruby-forum.com/t/assiging-an-attribute-in-rhtml/49953>\
**Category:** Rails\
**Created:** [December 11, 2005, 12:06am UTC](https://www.ruby-forum.com/t/assiging-an-attribute-in-rhtml/49953 "2005-12-11T00:06:26Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![jason](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dc4da7/32.png) [@jason](https://www.ruby-forum.com/u/jason)\
**Post date:** [December 11, 2005, 12:06am UTC](https://www.ruby-forum.com/t/assiging-an-attribute-in-rhtml/49953/1 "2005-12-11T00:06:26Z")

</div>

This might be a stupid question, but I am quite the noob and I can’t  
find it in agile.

I have this in my html:

\<%= dynamic content %\>

and I want to put

\<%= dynamic content %\>

so I can put it as a target from another page.

cheers,

Jason

---

<div class="post-metadata">

**Author:** ![jason](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dc4da7/32.png) [@jason](https://www.ruby-forum.com/u/jason)\
**Post date:** [December 11, 2005, 12:37am UTC](https://www.ruby-forum.com/t/assiging-an-attribute-in-rhtml/49953/2 "2005-12-11T00:37:50Z")

</div>

On 12/10/05, Jason [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> \<%= dynamic content %\>

\<%= dynamic content  
%\>

---

<div class="post-metadata">

**Author:** ![jason](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dc4da7/32.png) [@jason](https://www.ruby-forum.com/u/jason)\
**Post date:** [December 11, 2005, 12:57am UTC](https://www.ruby-forum.com/t/assiging-an-attribute-in-rhtml/49953/3 "2005-12-11T00:57:12Z")

</div>

jeremyevans0 wrote:

> On 12/10/05, Jason [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > \<%= dynamic content %\>
> 
> \<%= dynamic content  
> %\>

Thanks. I’m saying to myself duuuh! Brainfart.

---

<div class="post-metadata">

**Author:** ![jason](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dc4da7/32.png) [@jason](https://www.ruby-forum.com/u/jason)\
**Post date:** [December 11, 2005, 1:30am UTC](https://www.ruby-forum.com/t/assiging-an-attribute-in-rhtml/49953/4 "2005-12-11T01:30:43Z")

</div>

On Dec 10, 2005, at 3:06 PM, Jason wrote:

> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

Try this:

> \<span class=‘class’ name=\<%= @ruby\_variable %\> \>\<%= dynamic content  
> %\>

-Ezra Z.  
WebMaster  
Yakima Herald-Republic Newspaper  
removed\_email\_address@domain.invalid  
509-577-7732

---

<div class="post-metadata">

**Author:** ![jason](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dc4da7/32.png) [@jason](https://www.ruby-forum.com/u/jason)\
**Post date:** [December 11, 2005, 1:38am UTC](https://www.ruby-forum.com/t/assiging-an-attribute-in-rhtml/49953/5 "2005-12-11T01:38:57Z")

</div>

I’m a noob also. I believe the answer is to rap the @ruby\_variable  
in the erb delimiters so

name=\<%=@ruby\_variable %\>

bruce

---

<div class="post-metadata">

**Author:** ![jason](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dc4da7/32.png) [@jason](https://www.ruby-forum.com/u/jason)\
**Post date:** [December 11, 2005, 3:49am UTC](https://www.ruby-forum.com/t/assiging-an-attribute-in-rhtml/49953/6 "2005-12-11T03:49:01Z")

</div>

You should quote the name. Avoid problems and make “good” html.

```
 <span class='class' name='<%= ruby_var %>'><%= dynamic content 

```

%\>

My current project uses many of these for using same structure with  
different  
classes:

```
 <span class='<%= class_var %>' id='<%= id_var %>'><%= dynamic 

```

content  
%\>

Also: ‘id’ should generally be used rather than ‘name’. I believe it’s  
safe  
to say that ‘id’ will respond  
everywhere ‘name’ would, plus ‘id’ can be used as an object: xyz.style…  
(But sometimes I use the same ‘name’ for multiple objects to do group  
operations: document.all(‘myButtons’).style…)

Rich C.

----- Original Message -----  
From: “Bruce B.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
To: [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Sent: Saturday, December 10, 2005 4:37 PM  
Subject: Re: [Rails] assiging an attribute in rhtml

---

<div class="post-metadata">

**Author:** ![jason](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dc4da7/32.png) [@jason](https://www.ruby-forum.com/u/jason)\
**Post date:** [December 11, 2005, 3:07am UTC](https://www.ruby-forum.com/t/assiging-an-attribute-in-rhtml/49953/7 "2005-12-11T03:07:34Z")

</div>

brucebalmer wrote:

> I’m a noob also. I believe the answer is to rap the @ruby\_variable  
> in the erb delimiters so
> 
> name=\<%=@ruby\_variable %\>
> 
> bruce

hey bruce, the solution jeremy posted works. I had thought that putting  
putting ruby code \<%= @variable %\> in quotes ‘\<%= @variable %\>’ would  
force a string and not ruby.

But that works.

---

<div class="post-metadata">

**Author:** ![jason](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dc4da7/32.png) [@jason](https://www.ruby-forum.com/u/jason)\
**Post date:** [December 12, 2005, 8:49pm UTC](https://www.ruby-forum.com/t/assiging-an-attribute-in-rhtml/49953/8 "2005-12-12T20:49:32Z")

</div>

By way of correction of myself…

> Also: ‘id’ should generally be used rather than ‘name’. I believe it’s safe  
> to say that ‘id’ will respond everywhere ‘name’ would…

You still need to use ‘name’ in form variables, ‘id’ is not adequate.

\<input type=text NAME=whatever…

Rich C.

----- Original Message -----  
From: “Rich C.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
To: [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Sent: Saturday, December 10, 2005 6:46 PM  
Subject: Re: [Rails] assiging an attribute in rhtml
