Hi all This isn''t doing what I expect it to. Can you give it a quick look-see if you have a moment? def user_navigation_helper content_tag(:div, :class =>"banner_right") do content_tag(:ul, :class => "wat-cf") do if current_user() content_tag(:li) { current_user.email } content_tag(:li) { link_to("Edit profile", edit_user_path(:current)) } content_tag(:li) { link_to("Logout", logout_path) } else content_tag(:li) { link_to("Login", login_path) } content_tag(:li) { link_to("Register", new_user_path) } end end end end I am getting just one of the two or thee <li> items. Is there a better/cleaner/correct way of doing this? Thanks! Pito -- 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 Apr 16, 8:26 pm, Pito Salas <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> I am getting just one of the two or thee <li> items. Is there a > better/cleaner/correct way of doing this? Thanks! >When used in this context, content_tag returns a string with corresponding fragment of html. Your innermost calls to content_tag aren''t doing anything with that result whereas you probably want to be concatenating them. Fred -- 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.
On Fri, Apr 16, 2010 at 3:26 PM, Pito Salas <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hi all > > This isn''t doing what I expect it to. Can you give it a quick look-see > if you have a moment? > > def user_navigation_helper > content_tag(:div, :class =>"banner_right") do > content_tag(:ul, :class => "wat-cf") do > if current_user() > content_tag(:li) { current_user.email } > content_tag(:li) { link_to("Edit profile", > edit_user_path(:current)) } > content_tag(:li) { link_to("Logout", logout_path) } > else > content_tag(:li) { link_to("Login", login_path) } > content_tag(:li) { link_to("Register", new_user_path) } > end > end > end > end > > I am getting just one of the two or thee <li> items. Is there a > better/cleaner/correct way of doing this? Thanks!one way: def user_navigation_helper content_tag(:div, :class =>"banner_right") do content_tag(:ul, :class => "wat-cf") do if current_user() [content_tag(:li) { current_user.email }, content_tag(:li) { link_to("Edit profile", edit_user_path(:current)) }, content_tag(:li) { link_to("Logout", logout_path) }]].join else [content_tag(:li) { link_to("Login", login_path) }, content_tag(:li) { link_to("Register", new_user_path) }].join end end end end -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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.
Thanks both!! So the code snippet below now works correctly.... Is there a more typical way of doing what I am doing or would you consider this idiomatic rails? -- PIto def user_navigation_helper content_tag(:div, :class =>"banner_right") do content_tag(:ul, :class => "wat-cf") do if current_user() content_tag(:li) { current_user.email } + content_tag(:li) { link_to("Edit profile", edit_user_path(:current)) } + content_tag(:li) { link_to("Logout", logout_path) } else content_tag(:li) { link_to("Login", login_path) } + content_tag(:li) { link_to("Register", new_user_path) } end end end end -- 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.