I am trying to add an inline-style to an element with HAML.
Somwhow, the style does not show up inside the tag - any idea whats wrong with it?
%span.proceed-to-checkout.four.columns.offset-by-six{ :style => (#order.empty? ? 'display: none;' : 'display: inline;)'}
You are not correctly closing last parenthesis. I think you can even remove them. Try:
{ :style => #order.empty? ? 'display: none;' : 'display: inline;' }
Related
Using simple_form v2.1.0 in a Rails 3.2.13 app. I have a simple_form where I want to have a checkbox show up with an inline label, and I want to have an "empty" normal label. This way, the label's container should remain in place and the checkbox will be properly positioned with the other form elements.
If I set :label => "" or :label => " " or :label => nil or don't provide a :label at all, I end up with the field name as the label.
If I set :label => false, the label and containing elements aren't rendered at all (so the checkbox appears at the far left of the page).
If I set :label => " ", I end up with the literal text , as expected.
It seems there is no way to tell simple form to leave the label there, just don't put any text in its container.
Here is an example form where I'm trying to setup an empty label for a checkbox with an inline label.
<%= simple_form_for #model ... %>
<%= f.input :sticky, :label => "", :inline_label => "Sticky?", :as => :boolean ... %>
<% end %>
But simple_form thinks it's smarter than me and defaults the label. I wish it only did that if I hadn't specifically supplied a label!
Try setting :label value to false.
UPDATE: Since SimpleForm is supposed to rely on ActionView to render the elements, you can use this hackish solution: set the label in your locale file to empty string, like this
en:
activerecord:
attributes:
model_name_underscored:
sticky: ' '
Have you tried removing the :label attribute in your input completely and instead using form.label for the empty label.
http://apidock.com/rails/ActionView/Helpers/FormHelper/label
Instead of using an empty label you could position your check box with CSS.
Was having similar troubles. In your form defaults just do this:
defaults: { :label => 'blanklabel', label_html: { class: 'blanklabel'}
Then in your CSS, just set the label text color to white:
.blanklabel { color: white; }
Trying to figure out how to use haml "link_to" with Ruby code in order to make an image on a page link to another page on the site. If possible I'd like to keep the nav static and fade the two pages in and out via a "Forward" and "Back" image. Any ideas? Just want to get the linking right first and then can go in and figure out the JQuery. Currently have the code below...
Thanks!!
.pad-bottom50
%div{:style => "position: absolute; top: 620px; left: 830px;"}
=link_to (image_tag(#page.photos[1].image_url(:full), :id => "#fade1", :class => "animated") if #page.photos[1].image?
.pad-top20
Syntax of link_to is
=link_to link_text, link_url, options
You missed the link_url. ie. to where the user should be taken when clicking on the image.
Here is a working example
=link_to(image_tag("http://goo.gl/FZUI3"), "http://en.wikipedia.org/wiki/Nyan_Cat", :id => "#fade1", :class => "animated")
You are not specifying the src for the link.
The syntax is:
link_to "Link Text", "/path-to-link"
To put an image in there:
image_tag "path-to-image"
link_to(image_tag("path-to-image"), "/path-to-link")
This code will make an image wrapped by a link pointing to /bacon if #page.photos[1].image?
link_to(image_tag(image_tag(#page.photos[1].image_url(:full), :id => "#fade1", :class => "animated")), "/bacon", :id => "bacon", :class => "bacon") if #page.photos[1].image?
You should first look at the parameters of a link_to tag . You will get to know about the parameters and what you can do with those parameters .
check this link
api doc
You can check all paramters of a method avilable in API Ruby on Rails
I want to use a Twitter Bootstrap popover to display a user avatar and email address, with the possibility of adding in more details at a later date.
I am having an issue getting the partial to render inside the content field of the link. The view code is below (in HAML).
%span.comment-username
=link_to comment.user_name, "#", "title" => comment.user_name,
"data-content" => "=render 'users/name_popover'",
class: "comment-user-name"
Currently, this will only produce the content code as a string.
Is there a way to do this so the partial will be inserted instead of the code as a string?
You want rails to actually evaluate the content of the string and not just show the string. The easiest way to do that would be:
%span.comment-username
=link_to comment.user_name, "#", "title" => comment.user_name,
"data-content" => "#{render 'users/name_popover'}",
class: "comment-user-name"
That should pass the render statement to rails and render your partial as expected.
Thanks for the answer jrc - it helped me find a solution.
My solution might be useful for other non HAML people like me:
`<%= link_to('Service History' , '#', :class => "popover-history", :rel => "popover", :"data-placement" => "bottom", :title => "Service History", :"data-content" => "#{render 'services/service_history'}") %>`
with
`$(function () {
$('.popover-history').popover({ html : true });
});`
I have a tooltip that use this html attribute "original-title".
I have tryed this:
content_tag(:span, '', :class => options[:pinfo_class], :original-title => options[:pinfo])
But it gives a error in view.
Then I have used this which works, but not with the tooltip.
content_tag(:span, '', :class => options[:pinfo_class], :original_title => options[:pinfo])
How do I force rails to use the :original-title ?
You can use a string as a hash key, like 'original-title' => options[:pinfo]. Should work.
Also, most strings can be converted to symbols via 'some-string'.to_sym method, or even defined as :'some-string'.
Topic question:
If i already have helper which returns me image according with parameter (true or false)
I called it like this
and it is returns me <img src=... />
I was thinking to use MvcContrib but i cant use <%= %> syntax in embedded blocks
Then i find out that it is possible to do like this:
p => "img tag src=/images/Available.png/>").Named.(“A”).DoNotEncode();
But i want to put conditions, somth that like that:
if(item.Availible)
column.For(p => "img tag src=/images/Available.gif").Named (“A”).DoNotEncode();
else
column.For(p => "img tag=/images/Notavailable.gif").Named(“A”).DoNotEncode();
i was tried to make it like this:
column.For(p => ((item.Availible==false) ? "img tag src=/images/Notavailable.png" : "img tag=/images/Availible.png").Named(“A”).DoNotEncode();
but it is doesn't working properly.
is there any way of doing this?
I think this is what you're looking for:
column.For(p => p.Available(true) ? "<img src=\"/images/Available.gif\">" : "<img src=\"/images/Notavailable.gif\">").Named("A").DoNotEncode();