link_to nesting

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 <div> 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:
<div class="button">
  Button
</div>

I'm doing this now:

<div class="button">
<%= link_to_remote 'Button',
      :url => { :action => 'add', :id => person },
      :update => 'added_people'%>
</div>

which of course generates something like
<div class="button>
   <a...
</div>

and I want

<a ....
<div.. /div>
</a>

Any suggestions?

RoaR_lion wrote:

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 <div> 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:
<div class="button">
  Button
</div>

I'm doing this now:

<div class="button">
<%= link_to_remote 'Button',
      :url => { :action => 'add', :id => person },
      :update => 'added_people'%>
</div>

which of course generates something like
<div class="button>
   <a...
</div>

and I want

<a ....
<div.. /div>
</a>

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 %>

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.