How do I escape a colon in HAML - haml

Can any one tell me how to write this in HAML?
<td mc:edit = "headline">
The colon between the "mc" and the "edit" is what's screwing me up.
I tried:
%td{:mc\:edit => "headline"}
%td{:mc:\edit => "headline"}
%td{:mc:plain:edit => "headline"}
%td{:mc:escape:edit => "headline"}
%td(mc:edit = "headline")
They all return errors.

Both, %td{"mc:edit": "headline"} or %td(mc:edit="headline") should work.
Using:
haml (4.0.7)
haml-rails (0.9.0)
ruby-2.3.0
rails (4.2.6)

Related

Using tr as label-input wrapper in simple-form

I may be old school,and I've been through many div/span attempts and swore off tables at one time, but there are just some good uses for tables, one of them, imho, is a form. I prefer to shade my label fields with a different background color. I've tried may ways, but if the input (actually either) side overflows the width, it will mess up the label background. I'd look at another attempt, but I really prefer a table approach.
In 2.x I set my configuration to:
config.wrappers :tag => :tr, :class => :input,
:hint_class => :field_with_hint, :error_class => :field_with_errors do |b|
b.use :label, :wrap_with => {:tag => :td, :class => :label}
b.use :input, :wrap_with => {:tag => :td, :class => :input}
b.use :hint, :wrap_with => { :tag => :span, :class => :hint }
b.use :error, :wrap_with => { :tag => :caption, :class => :error }
Works great!, except for errors. I first had it as a span and it went to the top of the table. I then set it to caption and, at least in Safari, it ends tbody and puts in the caption and starts another tbody - but it screws up the table flow.
Is there a way I can force the error to be in the input wrapper? Or any other approach? I'd even accept (and maybe this is what I should do) putting the error in the main message like the scaffold approach. Didn't think about that until I started to write this, but I guess I could not use simple forms error stuff and go back to the scaffold approach.
At least I think you can do that. For instance, I didn't know (and could not find in documentation - but I didn't look real hard!) that you could use regular form_for input (e.g., f.text_field) mixed with f.input. Great for things like putting City, St, Zip on one row.
I guess I should answer my own question. I ended up not using Simple Forms error notification and went back to the scaffold method.
I configured my wrappers as follows:
config.wrappers :tag => :tr, :class => :input,
:hint_class => :field_with_hint, :error_class => :field_with_errors do |b|
b.use :label, :wrap_with => {:tag => :td, :class => :label}
b.use :input, :wrap_with => {:tag => :td, :class => :input}
Wrote a helper method for errors:
def show_form_errors(instance)
if instance.errors.any?
errors = content_tag(:h2, pluralize(instance.errors.count, "error") +"prohibited this project from being saved:")
list = content_tag :ul do
e = ""
instance.errors.full_messages.each do |msg|
e <<"<li>#{msg}</li>"
end
e.html_safe
end
return content_tag(:div, (errors + list),:id => "error_explanation").html_safe
end
end
# instead of
# = f.error_notification
# I used
# = show_form_errors(#event)
Had to tweak the CSS for error_explanation because of how I had borders defined on my table rows (just border-bottom) and add !important to wrap the tr with a red border:
.field_with_errors {
padding: 2px;
border:solid 3px red!important;
background-color:pink;
}
Works fine and I am content with this method.

how to not show default locale in url for rails 3.0.11 app using translate_routes gem

I have a rails 3.0.11 application.
I am using the translate_routes gem which seems to have a bug so I can't do wildcard matches with locales as follows:
routes.rb
MySite::Application.routes.draw do
.
.
.
match '/:locale/*path' => 'site#show', :as => 'cms'
ActionDispatch::Routing::Translator.translate_from_file('config/locales/routes.yml')
end
SO I have had to add the following:
ActionDispatch::Routing::Translator.translate_from_file('config/locales/routes.yml')
match '/(:locale)/*path' => 'cms#show', :as => 'cms', :locale => /fr|ar|en/
This works in so much as the paths have the locales and the system can find the routes. However it shows
en/somepage
when I want
/
for the default.
Any ideas on how to not show the default locale?
Have you tried overwriting default_url_options like this?
def default_url_options(options={})
options.merge!({ :locale => ((I18n.locale == I18n.default_locale) ? nil : I18n.locale) })
end

The atrr "page_gap" of will_paginate useless?

Following the code,
<%= will_paginate #bls, :container => false, :previous_label => "上一页", :next_label => "下一页", :page_gap => "......", :inner_window => 0, :outer_window => 0 %>
Everything (like previous_label) except "page_gap" helps, the gap on the page is not "......" but is "Page gap". I use the version 3.0.2(the lastest).
https://github.com/mislav/will_paginate/pull/213
If there is a customized page gap, it should be used instead of the default one.
Update:
Just try use config file. It's very useful. Here

haml display address

album/show.html.haml
#comment_list= render :partial => 'shared/comments', :locals => { :commentable => #album }
shared/_comments.html.haml
#comments
= commentable.comments.each do |comment|
= comment.content
display
Hello #<Comment:0x7f668f037710>
why is address displaying? How to remove it?
What happens if you remove the = before commentable?
I think the parser understand that you are mixIng erb and haml. Try removing = and inserting - instead.

Is there a new syntax for `url_for` in rails 3?

In a plugin helper, I have:
include Rails.application.routes.url_helpers
url_for(:only_path => true, :controller => 'people', :action => 'new')
Note that uses the new include syntax, that part works ok. But I get an error:
undefined local variable or method `controller' for #<ActionView::Helpers::InstanceTag:0x311ddf4>
Is there a new way to specify this, like maybe 'controller#action' ? what's the key?
url_for should work as usual, see http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-url_for
I checked it on my console:
ruby-1.9.2-head > include Rails.application.routes.url_helpers
=> Object
ruby-1.9.2-head > url_for(:only_path => true, :controller => 'admin/providers', :action
=> 'new')
=> "/admin/providers/new"
Maybe the error doesn't occur in the url_for because your error messages says ActionView::Helpers::InstanceTag this sounds like you're using some kind of Tag like link_to etc. Did you think about this?
Best regards
Simon