Generating relative url in Middleman in tag's attribute - relative-path

I need to get a relative url in the data-original attribute of img tag like this:
<img data-original="../imf/72932.png" src="../i/72932.jpg" />
But I'm getting
<img data-original="/imf/10163.jpg" src="../i/10163.jpg" />
As you can see, by setting set :relative_links, true in config.rb I can get a relative link in img's src but not in the data-original attribute with:
<%= image_tag img_url, { "data-original" => original_path } %>
where original-path is defined like this
<% original-path = "/imf/#{ wiz.file }" %>
It works of course when the site is generated dynamically in development but not when it is built statically. Is there any way to make original_path work like a relative path?

Related

Re-using a stimulus action elsewhere on the page?

I am wiring up a slack clone (html/css) and have it so that the reference drawer opens/closes when I click on the x. I am wanting to also open/close it from the navigation area and thought I could just take the same link_to and call it from a different part of the page.
But when I do that, if I'm calling it from within a different target, I get an error
Error invoking action "click->navigation#toggle_reference_drawer"
Error: Missing target element "navigation.referenceDrawer"
How can I use code inside a data-target to trigger a different data-target?
i.e. what I'm trying to get working is
--navigation partial (link_to doesn't work) --
<div data-navigation-target="storyNavLinks">
<div class ="story">
<%= link_to "[x]", "#", data: { action: "click->navigation#hide_reference_drawer" } %>
</div>
</div>
-- application partial (link_to works) --
<div data-navigation-target="referenceDrawer">
<div class='reference box'>
<%= link_to "[x]", "#", data: { action: "click->navigation#hide_reference_drawer" } %>
</div>
</div>
Not sure where I'm going wrong.. I figured as long as the target being referenced is unique and on the page it shouldn't matter where it's being called from?
You have to make sure your data-controller attribute is on an element that wraps both targets. If that is not possible you can always include the controller twice but the targets will only be scoped to each instance so you will need to add them twice as well.

Including logo when sending email via postal

In my MVC4 application, I am using the postal package for sending emails.
I am trying to include a logo via an <img> tag, but it's not working.
How can I include my company logo?
Controller Action:
public ActionResult Index()
{
dynamic email = new Email("Example");
email.To = "xxxxx#xxxxxx";
email.FunnyLink = "haiii";
email.Send();
return View();
}
View:
To: #ViewBag.To From: lolcats#website.com
Subject: Important Message
<div style="background-color:aqua;">
Hello, You wanted important web links right?
Check out this: #ViewBag.FunnyLink
<br />
<img src="~/Images/Logo.png" />
</div>
You need to use full absolute image urls like this-
<img src="#Request.Url.GetLeftPart(UriPartial.Authority)/Images/Logo.png" />
or
If you're having html based files then you should send the domain name just like the other data you're passing into the view like this-
<img src="#ViewBag.DomainName/Images/Logo.png" />
When your email would be received by the users then the content of your email would not resolve the image path from relative urls like this -
/Images/logo.png {this will not work}
So the images can only be fetched if having full domain path.
You could use Html extension as shown below. You can refer here for more details.
<div style="background-color:aqua;">
Hello, You wanted important web links right?
Check out this: #ViewBag.FunnyLink
<br />
#Html.EmbedImage("~/Images/Logo.png")
</div>

different partial rendering for the same object rails 3.1

I have in comments/create.js.erb that:
$("<%= escape_javascript(render(:partial => #comment))%>").hide().prependTo("#comments").fadeIn(1500);
$('#comment_content').attr('value','');
I have in comments/_comment.html.erb
<div class="comment">
content
</div>
This code its for form that is in comments/views/show.html.erb
I want render other partial because My new form is in comments/views/index.html.erb.
How can I render other partial for different view?
I had check for add to create.js.erb for example:
$("<%= escape_javascript(render(:partial => "other_partial"))%>").hide().prependTo("#other_div").fadeIn(1500);
But this dont working for me :(

In Rails 3, how can you make a div a button (a clickable div that links to a new page)

I know that there are options to do this manually, such as here : How do you make the entire DIV clickable to go to another page?
However, in Rails 3 we make links like this:
<%= link_to "name", url %>
And I am wondering -- is there a proper Rails way to make a whole div a button. I realize I could make a button. However, let's say I want to fill it with content like text and a picture - then how would I make that whole div clickable in a rails way?
For example:
<%= #story.title %>
<%= #story.blurb %>
In this example, I would want to make #story clickable, with the rails generated content that I specified.. Any ideas?
For those interested, the answer is:
<div class="class_name">
<%= link_to content_tag(:span, "Text for the LInk"), route %>
</div>
And then, in the CSS set .class_name to position:relative; and:
.class_name span {
width:100%;
height:100%;
position:absolute;
z-index:2;
top:0px;
left:0px;
}
The link will now assume the size of its parent container, and thus give the impression the whole container is a link.
I think that button_to is what you need :
http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-button_to
I might use jquery if you really wanted to do this
$(document).ready(function() {
$('#somediv').click(function(event){
document.location = 'http://someplace.com';
});
});
You can't make a "clickable" raw div like that in a rails way... the concept doesn't make any sense. That's just not how it works
(added missing close parens for click)
not tested

Rails 3: how to render text file in-line?

All.
A Rails n00b here...
I'm writing an application that reports the status of a transaction.
Some of the content in the rendered HTML comes from instance variables
initialized in the controller, while other content comes from text files
(e.g., log files) that I want to render in the HTML using <pre> tags.
What is the "Rails Way" to do this?
Thank you for your time...
<pre>
<%= render :file => '/tmp/test.log' %>
</pre>
Here you go: http://edgeguides.rubyonrails.org/layouts_and_rendering.html
In some cases (when the file is not small and loading it is connected with a delay), I prefer to load the page content and then to use jQuery ajax request to load the file content.
For example, let's say I have a model with file path attribute. In the view layout I am doing something like this:
<pre data-source=" <%= (#file.path) %>"></pre>
Then in the corresponding js file I am loading the context like this:
$(document).ready ->
$.ajax(
url: $("pre").data("source")
context: document.body
).done (response) ->
$("pre").html response
return
return
Of course you can check the jQuery ajax documentation for more options. For example, you can render the pre tag with loading like this:
<pre data-source=" <%= (#file.path) %>"><div class="loading"></pre>
or use other jQuery animations as well.