# Info on View Helper Methods

**URL:** <https://www.ruby-forum.com/t/info-on-view-helper-methods/153420>\
**Category:** Rails\
**Created:** [November 17, 2008, 12:16am UTC](https://www.ruby-forum.com/t/info-on-view-helper-methods/153420 "2008-11-17T00:16:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dr\_gavin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c37758/32.png) [@dr\_gavin](https://www.ruby-forum.com/u/dr_gavin)\
**Post date:** [November 17, 2008, 12:16am UTC](https://www.ruby-forum.com/t/info-on-view-helper-methods/153420/1 "2008-11-17T00:16:52Z")

</div>

Hi there!  
Can anyone point me in the direction of some resources for building  
your own view helpers?

I want to acheive something simple:

In the view,

\<%= button do %\>  
Delete  
\<% end %\>

will give

 Delete

in the source?

Can anybody help out?  
thanks

---

<div class="post-metadata">

**Author:** ![dr\_gavin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c37758/32.png) [@dr\_gavin](https://www.ruby-forum.com/u/dr_gavin)\
**Post date:** [November 17, 2008, 1:18am UTC](https://www.ruby-forum.com/t/info-on-view-helper-methods/153420/2 "2008-11-17T01:18:54Z")

</div>

On Sun, Nov 16, 2008 at 11:58 PM, Dr\_Gavin [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Delete  
> Can anybody help out?  
> thanks

mmmh, I guess

def button  
content\_tag :div, :class =\> “button”  
end

will to the trick. but it is just because it is simple… If you have  
something complex, you hav to play with capture()

Another simple way, is to play with partials. you can use

def button  
render :layout =\> ‘/shared/button’  
end

# app/view/shared/\_button.html.erb

 \<%= yield %\>

hope it will help

–  
Gabriel L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![dr\_gavin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c37758/32.png) [@dr\_gavin](https://www.ruby-forum.com/u/dr_gavin)\
**Post date:** [November 24, 2008, 12:53pm UTC](https://www.ruby-forum.com/t/info-on-view-helper-methods/153420/3 "2008-11-24T12:53:24Z")

</div>

Hey Gabriel - thanks for the advice.

Sorry for the late reply.

I’ve managed to get this working

def delete\_button\_for(value, path, confirm=nil, id=nil)  
content\_tag :div,(link\_to\_remote value, {:url =\> path,  
:method =\> :delete, :confirm =\> confirm}), :class =\>  
‘button’, :id =\> id  
end

😃

Thanks again

Gavin
