Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4558848
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T17:42:20+00:00 2026-05-21T17:42:20+00:00

I have the following haml: 9 %strong Asked by: 10 = link_to @user.full_name, user_path(@user)

  • 0

I have the following haml:

  9       %strong Asked by:   
 10       = link_to @user.full_name, user_path(@user)     
 11       .small= "(#{@question.created_at.strftime("%B %d, %Y")})" 

This currently puts the link and the date on separate lines, when it should look like “link (date)” and date has a class span of small…..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T17:42:21+00:00Added an answer on May 21, 2026 at 5:42 pm

    Your code will generate something like this html:

    <strong>Asked by:</strong>
    <a href="userpath">User name</a>
    <div class='small'>April 26, 2011</div>
    

    When you use something like .small (i.e. use the dot without specifying the element type) haml creates an implicit div. Since div elements are by default block level elements the date will be in a new block and so will appear on a new line. In order to get it to appear on the same line, you’ll need an inline level element.

    You could change the css for the “small” class to explicitly make it display inline, but html already provides an inline version of the div – the span, so you can change the last line from

    .small= "(#{@question.created_at.strftime("%B %d, %Y")})" 
    

    to

    %span.small= "(#{@question.created_at.strftime("%B %d, %Y")})" 
    

    which will give you

    <strong>Asked by:</strong>
    <a href="userpath">User name</a>
    <span class='small'>April 26, 2011</span>
    

    which are all inline elements, so will appear as one line.

    As for having it all on the same line in the haml, I don’t think that’s possible with plain haml syntax. Haml uses the indentation and whitespace in order to determine what to do, and having just one line means there’s no indentation.

    The haml FAQ says:

    Expressing the structure of a document and expressing inline formatting are two very different problems. Haml is mostly designed for structure, so the best way to deal with formatting is to leave it to other languages that are designed for it.

    You seem to be at the edge of what haml is intended for. You could write your html directly if you really wanted it all on one line:

    <strong>Asked by:</strong> #{link_to @user.full_name, user_path(@user)} <span class="small">(#{@question.created_at.strftime("%B %d, %Y")})</span>
    

    or perhaps you could create a helper that will generate the block for you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have in my app/views/bar/index.html.haml the following %p= render partial: 'foo', collection: @foos the
I have following question on adobe omniture How we can register an iPhone app
I have the following Haml code: %ul#sub-nav %li.li1 %a{:href => /dsadasd/} dasdasd %li.li2 %a.selected{:href
I have the following line of haml: =form_tag :action => 'create', :controller => 'comments',
I'm running Rails 3.1.1, RSpec 2.7.0 and HAML 3.1.3. Say I have the following
In a haml file I have an element such as the following: %th Movie
I have a Rails app (v2.3.8) using HAML (v3.0.25). My application.html.haml currently has the
I have the following HAML written to take the place of a scaffold index
I have the following html.erb code that I'm looking to move to Haml: <span
Using the (intentionally) strange multi-line format for HAML, I'd like to have the following

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.