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 7672769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:21:44+00:00 2026-05-31T16:21:44+00:00

I’m having a hard time rendering a view in Haml,using MongoMapper for a small

  • 0

I’m having a hard time rendering a view in Haml,using MongoMapper for a small Sinatra app I’m working on.
I have this here which I know the query is not bad:

get '/admin' do
  protected!
  @title = "admin"

  @total_items = Item.all(:order=>:itemtype.desc)

  haml :admin, :locals => @total_items
end

Now, the problem is , I’m trying to use the @total_items instance variable in my Haml view to be able to output the keys in an ordered list after retrieving each item with the loop:

%div 
  %img     
  - @total_items.each do |item|
  %h3= item

and I’m stuck.How do I access the keys? Thanks!

  • 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-31T16:21:45+00:00Added an answer on May 31, 2026 at 4:21 pm

    There are some issues with your code at hand:

    If you use instance variables you don’t need to use :locals. They are accessible in your views anyway. So either use total_items and make use of :locals or use @total_items and access them as that in your views. BTW, :locals are used like that:

    haml  :admin, :locals => {:items => total_items}
    

    then you can access in admin.haml your total_items as items

    Back to your question: In your admin.haml file there is a small error that is easy to fix: Make sure you get the indentation right. After all this is what haml is about:

    %div 
      %img     
      -items.each do |item| # I use the above mentioned :locals with items instead of total_items
        %h3= item
    

    Edit:
    You could even keep it more simple by querying the items from your view:

    %div 
      %img     
      -Item.all(:order=>:itemtype.desc).each do |item|
        %h3= item
    

    PS: What is the %img tag good for? It’s not used in your example.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
We're building an app, our first using Rails 3, and we're having to build
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
I have thousands of HTML files to process using Groovy/Java and I need to
I am using Paperclip to handle profile photo uploads in my app. They upload

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.