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 <div class=''button''> Delete </div> in the source? Can anybody help out? thanks --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Sun, Nov 16, 2008 at 11:58 PM, Dr_Gavin <dr_gavin-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org> wrote:> > 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 > > <div class=''button''> > Delete > </div> > > in the source? > > Can anybody help out? > thanksmmmh, 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 <div class="button"> <%= yield %> </div> hope it will help -- Gabriel Laskar <bibi.skuk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 :D Thanks again Gavin On 17 Nov, 00:17, "Gabriel Laskar" <bibi.s...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Sun, Nov 16, 2008 at 11:58 PM, Dr_Gavin <dr_ga...-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org> wrote: > > > 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 > > > <div class=''button''> > > Delete > > </div> > > > in the source? > > > 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 > <div class="button"> > <%= yield %> > </div> > > hope it will help > > -- > Gabriel Laskar <bibi.s...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---