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();
Related
Right now I have some filler code in a mockup such as the following:
%img{:alt => "image description", :src => "img/img-11.jpg"}
Ideally though, I need to reference img-11.jpg from the asset pipeline as I do in my CSS:
<%= asset_path "img-11.jpg" %>
How does one rewrite the markup above to call asset_path within the context of a HAML template?
HAML is basically the same, but without the surrounding brackets if you're doing it inline:
= asset_path "img-11.jpg"
Otherwise you should be able to use it in the definition:
%img{:alt => "image description", :src => asset_path("img-11.jpg")}
In this case, use = image_tag('img-11.jpg', alt: 'Image Description'), but in the general case, use = function_name_or_ruby_code to evaluate any arbitrary Ruby and output the result.
You can use - ruby_code to evaluate Ruby without outputting the result.
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;' }
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 });
});`
Here is my div. What is the syntax for adding another conditional class?
.progress{ :class => list.overdue? ? "progress-danger" : "" }
I essential want to add list.dirty? ? "progress-warning" : ""
But what is the right way to fit that in along side the list.overdue? part?
Why dont you take it to a helper
View code
.progress{ :class => check_list_over_due }
Helper Code
def check_list_over_due
if condition
'classname'
elsif condition
'classname'
else
'classname'
end
end
I don't know if it's "right" per se, but this should work:
:class => [list.overdue? ? "progress-danger" : nil,
list.dirty? ? "progress-warning" : nil].compact.join(" ")
I think the best way is to write helper, like "progress_bar_class(list)" and implement all logic in light structurized code.