-%>' (Minus Sign) at the End of a Erb Sequence

-% ' (minus sign) at the end of a ERb sequence

Before Rails 3, ERB adds additional spaces before and after the value when rendering the HTML content. In HTML spaces are not significant, except when you are using special tags such as <pre>.

Using the - sign forced ERB to avoid additional spaces.

This is completely useless in Rails 3.

Iterating over XML with Nokogiri in ERB leaves '0' char at the end

Seems like you output the whole result of each, while you probably want to output the iterated values:

<% @template.css('field').each do |field_node| %>
<%= raw(field_node.text) %>
<% end %>

How to create a rails checkbox form?


<% for interest in Interest.find(:all) %>
<%= check_box_tag "user[interest_ids][]", interest.id, @user.interests.include?(interest) %>
<%= interest.name %>
<% end %>

Re-ordering hash items to have some appear at the end

You can try following,

(hash.keys - end_keys + end_keys).map { |key| [key, hash[key]] }.to_h

Python range() with negative strides

You can specify the stride (including a negative stride) as the third argument, so

range(10,-11,-1)

gives

[10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10] 

In general, it doesn't cost anything to try. You can simply type this into the interpreter and see what it does.

This is all documented here as:

range(start, stop[, step])

but mostly I'd like to encourage you to play around and see what happens. As you can see, your intuition was spot on.



Related Topics



Leave a reply



Submit