# Link\_to nesting

**URL:** <https://www.ruby-forum.com/t/link-to-nesting/132899>\
**Category:** Rails\
**Created:** [March 25, 2008, 5:50pm UTC](https://www.ruby-forum.com/t/link-to-nesting/132899 "2008-03-25T17:50:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![RoaR\_lion](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/3ec8ea/32.png) [@RoaR\_lion](https://www.ruby-forum.com/u/RoaR_lion)\
**Post date:** [March 25, 2008, 5:50pm UTC](https://www.ruby-forum.com/t/link-to-nesting/132899/1 "2008-03-25T17:50:41Z")

</div>

Hello, I’ve just started using RoR this month, and am building a web  
app to help me learn the framework and the ruby language.

I have a basic and hopefully straightforward question for you guys,  
since I can’t seem to find the answer on the internet or in my copy of  
agile.  
I thought I posted this same question here yesterday but now couldn’t  
find it, and was told that I’m not even in the group?? If someone  
remembers seeing a similar question, please do tell, I feel like it’s  
not here, but I hate it when people re-post questions so I hope I’m  
not doing the same.

I have

 tags with nested text setup in the page acting as  
buttons. I would like to use these buttons with link\_to and  
link\_to\_remote. I haven’t yet figured out a way to get the generated  
anchor tags to nest other page elements inside. Now I have the  
buttons, but I have to click the text to get the link to work rather  
than having the whole div and everything in it act as a link.

html tags:

 Button

I’m doing this now:

\<%= link\_to\_remote 'Button', :url =\> { :action =\> 'add', :id =\> person }, :update =\> 'added\_people'%\>

which of course generates something like

\<div class="button\> \<a... \</div\> \<p\>and I want\</p\> \<p\>\<a …\<br\> \<div… /div\>\<br\> \</a\>\</p\> \<p\>Any suggestions?\</p\>

---

<div class="post-metadata">

**Author:** ![RoaR\_lion](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/3ec8ea/32.png) [@RoaR\_lion](https://www.ruby-forum.com/u/RoaR_lion)\
**Post date:** [March 25, 2008, 6:12pm UTC](https://www.ruby-forum.com/t/link-to-nesting/132899/2 "2008-03-25T18:12:05Z")

</div>

RoaR\_lion wrote:

> not doing the same.  
> Button  
> which of course generates something like  
> Any suggestions?

I haven’t tried this myself, but…

How about a helper. If you define a helper such as.

def build\_button(label)  
content\_tag(:div, “some stuff inside the button, such as #{label}”,  
:class =\> :button)  
end

Then in your view, call \<%= link\_to\_remote build\_button(‘Add’), :url =\>  
etc. etc. etc %\>

–  
[http://www.5valleys.com/](http://www.5valleys.com/)

[http://www.workingwithrails.com/person/8078](http://www.workingwithrails.com/person/8078)

---

<div class="post-metadata">

**Author:** ![RoaR\_lion](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/3ec8ea/32.png) [@RoaR\_lion](https://www.ruby-forum.com/u/RoaR_lion)\
**Post date:** [March 26, 2008, 5:30pm UTC](https://www.ruby-forum.com/t/link-to-nesting/132899/3 "2008-03-26T17:30:41Z")

</div>

Thanks Jon,

I’m going to keep what I have for now because I’m not sure exactly how  
the final version will look, but I’ll keep your suggestion in mind.

Thanks again.
