Hi Rcommunity! small refactoring question here. This is code: def login_block ret = "" ret += "<div class=''right wrapper''>" ret +="<strong>#{current_user_full_name}</strong>" ret += "<span>|</span>" ret += image_tag("logout.png") ret += "<span>#{link_to t(''logout''),''#'',:id => ''fb_logout''}</span>" ret += "</div>" ret.html_safe end is there a way to get rid of those ugly ret += ? -- Posted via http://www.ruby-forum.com/. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Use a partial? -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Here''s one way to refactor it using an array and content_tag. content = [ content_tag(:strong, current_user_full_name), content_tag(:span, "|"), image_tag("logout.png"), content_tag(:span, link_to(t(''logout''), ''#'', :id => ''fb_logout'')) ] return content_tag(:div, content.join("\n"), :class => "right wrapper").html_safe -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
ret = <<EOS <div class=''right wrapper''>" <strong>#{current_user_full_name}</strong>" ...... EOS On Apr 12, 8:48 am, Burebista <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hi Rcommunity! > > small refactoring question here. This is code: > > def login_block > ret = "" > ret += "<div class=''right wrapper''>" > ret +="<strong>#{current_user_full_name}</strong>" > ret += "<span>|</span>" > ret += image_tag("logout.png") > ret += "<span>#{link_to t(''logout''),''#'',:id => > ''fb_logout''}</span>" > ret += "</div>" > > ret.html_safe > end > > is there a way to get rid of those ugly ret += ? > > -- > Posted viahttp://www.ruby-forum.com/.-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
Thank you! Finally I can see real world example of heredocs! -- Posted via http://www.ruby-forum.com/. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Tue, Apr 12, 2011 at 8:48 PM, Burebista <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hi Rcommunity! > > small refactoring question here. This is code: > > def login_block > ret = "" > ret += "<div class=''right wrapper''>" > ret +="<strong>#{current_user_full_name}</strong>" > ret += "<span>|</span>" > ret += image_tag("logout.png") > ret += "<span>#{link_to t(''logout''),''#'',:id => > ''fb_logout''}</span>" > ret += "</div>" > > ret.html_safe > end > >if you''re using rails3, you can use a content_tag with a block content_tag :div, {:class => ''right wrapper''}, false do content_tag(:strong, current_user_full_name) + content_tag(:span, ''|'') + image_tag("logout.png") + content_tag(:span, link_to(t(''logout''),''#'',:id => ''fb_logout'') end content_tag accepts a boolean last attribute if you want to set the content as html_safe.> is there a way to get rid of those ugly ret += ? > > -- > Posted via http://www.ruby-forum.com/. > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- ------------------------------------------------------------- visit my blog at http://jimlabs.heroku.com -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.