haml

render a partial from jquery and haml

Hi guys, The functionality I plan on doing is to insert some form elements depending on a number chosen from a select tag. I have a select tag called for number_of_passengers, and i plan to dynamically append new passenger fields for the number chosen. Say I select 2 from number_of_passengers, then 2 forms should appear in a fieldset. ...

Escape forward slash in Ruby url helper

I'm trying to setup a very basic id="thisFileName" in my staticMatic project. So far I've managed to apply the following to an /index.html (the HAML output): - @slug = current_page.gsub(/\.html/, '') Which returns "/index". However - I'd like to remove the / at the start so that it reads /index... Any tips or directions for where ...

Can HAML do a "capture", kind of like a render_to_string in Ruby on Rails?

I heard that HAML has a capture function that can do something like Ruby on Rails's render_to_string, but can't find info on it. Actually, in View, we can use aString = render :partial ... and render actually works the same as render_to_string (as on Rail 2.2.2). But is there also an HAML way of doing it by capture? ...

Append class if condition is true in Haml (with Rails)

If post.published? .post / Post stuff Otherwise .post.gray / Post stuff I've implemented this with rails helper and it seems ugly. = content_tag :div, :class => "post" + (" gray" unless post.published?).to_s do / Post stuff Second variant: = content_tag :div, :class => "post" + (post.published? ? "" : " gray") do / Post...

How to do an if/else in HAML without repeating indented code

Depending on if a user is signed in or not, I'd like to print a different kind of %body-tag. This is how I currently do it: - if defined? @user %body(data-account="#{@user.account}") %h1 Welcome -# all my content - else %body %h1 Welcome -# all my content As you can see there's a lot of duplicated code in there. H...

How to validate an Ajax Form Submit (remote_form_tag) ?

I have an ajax mail form like - form_remote_tag :url=>mails_path,:condition=>"validate_mail()", :html => {:id=>"mailform",:method => :post, :class => 'ajax',:style=>"padding:15px;" } do |form| .gimmespace Naam %br = text_field_tag :name,params[:name],:class=>"title required" .gimmespace Telefoonnumm...

HAML: form_tag problem (indentation?)

Hello! I'm making "user settings form", and stuck with HAML: = form_tag('/') - [1,2,3].each do |i| = check_box_tag "accept#{i}" = submit_tag This results in "syntax error, unexpected kENSURE, expecting $end". The working variant is = form_tag('/') - [1,2,3].each do |i| = check_box_tag "accept#{i}" = s...

How to write a helper in Ruby on Rails to capture Haml blocks?

I am writing a Rails helper method that will add wrapper html to captured content blocks and replace content_for method, such as - content_for :header do //haml code ..would become - content :header do //haml code In order to do this I am using Haml and Ruby blocks. This is what it looks like def content(name,&block) content_fo...

Displaying the next lines and white spaces in HAML

I use a text area to collect comments from the user. The text area preserves the next line and white space indentation. While displaying the comment in a p tag the next line and white space indentation at the beginning of the line are lost. I enter the following text in the text area: Lorem ipsum dolor sit amet, consectetur adipisic...

Sinatra, select from Datamapper pass to Haml

I'm doing a brief exercise, condensed below. The issue I'm having is that I'm able to pass a selection of all tickets, but not a selection of one ticket. At / there is no problem listing all the tickets, at endpoint for a ticket I get: NoMethodError at /pi2l9ulnw undefined method `slug' for # I'm relatively new to Ruby and cutting and ...

Collection Select in HAML fails to wrap correctly.

Does anyone know why %select{:name => "dropdown"} expand » - for say_text in @available_says %option = h say_text in HAML resolves to <select name='dropdown'></select> <option>a</option> <option>b</option> <option>c</option> in HTML? It's stymieing my dropdown completely and the documentation all says "That should work." I can't i...

Datamapper, Sinatra, Haml : attaching and rendering Comments from a post

I have a model Ticket which has n Comments belonging to it (many to one relationship). The issue is that I can not render any of the comments nor does the form post the comments to the database. I can kinda sorta do this from irb. I can add comments to tickets.comments, but I cannot pull individual comments - I can pull up the collect...

Rails + Haml: How to unescape tag parameter?

I'm trying to accomplish the following content in source code: <div id="box<%=id%>"></div> Without escaping any signs in Haml. %div{ :id => "box_<%=id%>" } produces <div id='box_&lt;%=id%&gt;'></div> Right now the only way I can do this with Haml is to use :plain filter and hardcode HTML without using any View Helpers. How can I...

haml formbuilder

I'm converting an old program over to haml and I've got a problem with my custom formbuilder. The problem is simply adding a line feed between a fields label and input tag. Here is the original FormBuilder: # Custom FormBuilder class SuperFormBuilder < ActionView::Helpers::FormBuilder # Create an array of helpers to override with o...

Strange Datamapper's behaviour

I have this code in my controller: @cats = DirCat.all And this in a view: %ul#menu = @cats.each do |item| %li = link_to item.title, "/catalog/#{item.id}/" And get strange output: <ul id='menu'> <li> <a href="/catalog/4/">hello</a> </li> <li> <a href="/catalog/5/">hello 1</...

How would you handle a mixed HAML/ERB team?

I'm a big Haml/Sass fan. Right now I work with a designer who prefers Erb and doesn't speak Haml. I find that working with Erb is slowing me down considerably, and it doesn't seem fair that he should have to pay for that time (he's the client & I'm paid hourly). The erb->haml converter works quite well these days, but I don't know if t...

inserting blocks of text in haml

In my Jekyll blog I use the include tag to put the contents of a file into the document. However if I attempt to do this with a HAML based document the indentation of the included text is wrong. :preserve does not work because it requires indentation. Is there a way to specify a block of text without depending on indentation? %html %b...

Automatic generation of CSS from SCSS/SASS with HAML and Rails

Hi, Is there a way to get your SCSS files to automatically generate new CSS each time a file is changed as part of Rails, without having to use sass --watch? Or is this just meant to happen anyway? By this I mean having rails do the watching for you, or maybe if it can recompile all SCSS every page load in development that is fine too....

HAML block returning `0` on yield?

I just upgraded to Rails3, Ruby 1.9.2 and the latest HAML gem. This code used to work: = allowed? do = link_to('New', new_video_path) Now allowed? yields 0. It works if I do: = allowed?{ link_to('New', new_video_path) } What gives? ...

Getting undefined method content_for()

Hi, my mac just broke and I had to migrate to an Ubuntu machine. I am working on an app that is already on production on an Ubuntu machine as well. I cloned this app into my new machine and all the view helpers seems to go missing, btw I am ussing HAML. I ran my specs and I am getting tons of : undefined method url_for for # und...