haml

How do I make an image link tag using haml in Rails?

僤鯓⒐⒋嵵緔 提交于 2019-11-28 21:20:54
问题 I have something like this in application.html.haml: #header = image_tag("header.jpg") How do I make that link to www.google.com, for example? Thanks 回答1: I do it this way: = link_to image_tag( 'header.jpg'), 'http://www.google.com' 来源: https://stackoverflow.com/questions/1202654/how-do-i-make-an-image-link-tag-using-haml-in-rails

Empty attribute with Ruby HAML

隐身守侯 提交于 2019-11-28 20:03:12
I'm implementing Schema microformats on a Ruby project using HAML and can't figure out how to set an empty attribute on a tag. I tried nil and false, but they simply do not shown. Example: <div itemscope> I'm tring to set an empty itemscope attribute. Code added from comment by @StrangeElement: My code: .agency.premium{:itemscope => true, :itemtype => 'schema.org/ProfessionalService';} :itemscope => true seems to be the recommended approach from HAML's documentation. I get the same result as I would get with :itemscope => '' , a XHTML-valid attribute with an empty value (i.e. <div itemscope=""

Get absolute (base) url in sinatra

落花浮王杯 提交于 2019-11-28 19:31:06
Right now, I do a get '/' do set :base_url, "#{request.env['rack.url_scheme']}://#{request.env['HTTP_HOST']}" # ... haml :index end to be able to use options.base_url in the HAML index.haml. But I am sure there is a far better, DRY, way of doing this. Yet I cannot see, nor find it. (I am new to Sinatra :)) Somehow, outside of get , I don't have request.env available, or so it seems. So putting it in an include did not work. How do you get your base url? A couple things. set is a class level method, which means you are modifying the whole app's state with each request The above is a problem

How to Show Error Messages Next to Field

☆樱花仙子☆ 提交于 2019-11-28 18:39:25
I have a form with input fields/labels etc. How do I get the error message to show up next to the field? instead of clumped together at the top? I am using devise, rails 3 I have this at the top of my form: = form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| - if resource.errors.any? #errorExplanation %h2 = pluralize(resource.errors.count, "error") prevented this user from being saved: %ul - resource.errors.full_messages.each do |msg| %li = msg fl00r You can use this - if @resource.errors[:field_name] ... Also useful link: http://guides.rubyonrails.org

put haml tags inside link_to helper

馋奶兔 提交于 2019-11-28 18:08:57
is it possible to add html-content inside a link_to helper in HAML? i tried this, but all i get is a syntax error: = link_to "Other page", "path/to/page.html" %span.icon Arrow expected output: <a href="path/to/page.html">Other Page<span class="icon">Arrow</span></a> You should use block = link_to "path/to/page.html" do Other page %span.icon Arrow Paul If anyone is still using Rails 2.x on a project, it looks like the accepted answer returns the block, thus duplicating the link in the markup. Very simple change: use - instead of = - link_to "path/to/page.html" do Other page %span.icon Arrow The

Rendering partial with locals in Haml?

泄露秘密 提交于 2019-11-28 17:50:31
I am learning Haml. My view files are like: show.html.haml: .content = render 'meeting_info', :locals => { :info => @info } and _meeting_info.html.haml: .detail %table %caption Meeting Informations of = info["meeting_name"] ... When I tried running this I got an undefined local variable or method 'info' error. Try this Without :locals and :partial .content = render 'meeting_info', :info => @info No need to specify locals. With :locals and :partial You should specify locals in following case i.e specifying :partial for render .content = render :partial => 'meeting_info', :locals => { :info =>

How do I make dynamic ids in Haml?

こ雲淡風輕ζ 提交于 2019-11-28 17:21:47
#item creates a div with id="item" .box#item creates a div with class="box" and id="item" .box#="item "+x creates a div with class="box" and a comment '#="item"+x' .box# ="item"+x throws "Illegal element: classes and ids must have values." How do I get set the id to a variable? EmFi There are two ways: The long form way (define the id as if it were a regular attribute): .box{:id => "item_#{x}"} produces this ( x is what ever x.to_s evaluates to): <div class="box" id="item_x"> The short form way: .box[x] produces the following assuming x is an instance of item : <div class="box item" id="item

Ruby methods within Javascript within HAML

家住魔仙堡 提交于 2019-11-28 16:57:44
问题 I have a jQuery script that adds a new field to a form, and this field contains dynamic information from an array. The problem is that I can't figure out how to add an array.each to populate the options of the select field within the javascript without breaking the HAML indentation and causing errors. Here is my best attempt that does not work: %script(type="text/javascript") $('#mylink').click(function() { $('#mylink').after('<select> - myarray.each do |options| <option value="#{options.id}"

Count number of selectors in a css file

你说的曾经没有我的故事 提交于 2019-11-28 15:48:51
is there an existing plugin/app/program/script/whatever that analyzes and counts the css selectors of a file? i want to check if the reason my css file is not working in IE is because my selector count is over 4095 (which im pretty sure is not) thanks! p.s. plus points if there's a haml/sass/compass solution jetli13 The following snippet can be run in the Firebug console in Firefox to count the total number of CSS selectors (not just CSS rules) and check whether it reaches the limit of 4095 selectors per stylesheet: var styleSheets = document.styleSheets, totalStyleSheets = styleSheets.length;

erb, haml or slim: which one do you suggest? And why? [closed]

不羁岁月 提交于 2019-11-28 15:14:24
I am learning Rails and I have seen these template engines. I have no experience with them (only erb). But as I am a beginner, I am really confused. Which one do you suggest and why? Erb, Haml or Slim? Please tell your reason for preferring one over the others. And if you have any other recommendations, please let us know. EDIT: I am NOT looking for a winner here. I just want to hear your opinions about them, their syntax, speed of execution, and so on. ERB is good mainly if you have a web designer that will work on plain HTML and does not know either haml or slim. This way he can write HTML