Use ERB to generate Anchor Name - ruby-on-rails

I'm trying to create Anchor tags using values in my DB for the name. That way it's easy for me to call them from another page.
<a name="<%= sailing_class.sort_order %>"</a>
But the value from sailing_class.sort_order never appears.
All help is greatly appreciated. I'm on Rails 3.2

You're missing a > (closing <a), so the html is not vaild, and an anchor should be with an id attribute instead of name . Try
<a id="<%= sailing_class.sort_order %>"></a>

Related

Thymeleaf editing th:field before action

I have a simple pagination that looks like
<ul class="pagination justify-content-end" th:field="*{page}">
<li class="page-item page-item disabled">
<a class="page-link" href="action">1</a>
</li>
</ul>
I would get the following behaviour with Thymeleaf. Clicking on the page and before submitting the action, the value of the th:field associated with the pagination should be changed by setting it to the th:value of the selected page. In other words, clicking on the page number should change the value of "*{page}" and then call the method. Is there any way to do that, for example, combining th:onclick with th:action?
Thymeleaf is a rendering engine, as such it can do nothing once the page is served to the end user. At best u can fill variables into javascript when rendering to achieve the desired result.
As for your described functionality the given code is far to limited or faulty to give a suggestion for a javascript solution, for one th:field on a non-input element doesn't do much. Also the shown href is just a simple href that doesnt interact in any way with the encapsulating th:field.

adding tooltip to zendesk home_page.hbs

I want to add tooltips for some "Categories" box in Zendesk, so when the user hang over one box then I can show a tooltip with more information about the "Category".
Problem is that I'm trying to use IF statement like this:
{{#if href == '/hc/en-us/categories/360001117812-Cow-Traffic' }}
{{#each categories}}
{{#if ../has_multiple_categories}}
<li class="blocks-item">
<a href='{{url}}' class="blocks-item-link">
{{#if href == 'url_to_compare' }}
<a class="tooltiptext">tooltip_text</a>
{{/if}}
<span class="blocks-item-title">{{name}}</span>
<span class="blocks-item-description">{{excerpt description}}</span>
As this IF is inside of a {{#if}} of the categories I want to select in this example only one link using the href to see if the mouse is over or not the box.
I already tried to add a helper in the script.js file but looks like it's not working, I remember that there was a way to use this IF and IS to be able to solve it.
Thanks!
I get a lot of help on this, at the end I found that the better way to solve this is using a {{#is}} statement, So it's possible to use {{#is name "Category Name"}} {{/is}}
And this option will do a comparation between the name of the Category and the name you are looking for, if the value it's equal then you can do something inside, if not then you can use an {{else}} between and do another thing over there.
{{#is name "Category Name"}}
<div class="tooltip1">{{name}}<span class="tooltiptext">{{excerpt description}}</span></div>
{{else}}
<span class="blocks-item-title">{{name}}</span>
{{/is}}
I used the "Excerpt description" to add the value of the tooltip inside Zendesk, and no need to add it manually in the home_page.hbs code.
I added 3 different tooltips and working fine now. Thank you all!

Refer fragment in href or attribute for thymleaf template

is it possible to use a fragment value inside an html attribute like href?
im trying something
<a th:href="~{text:test::text-login}">Tada</a>`
but url comes out like
LOGIN</th:block>">Tada
Im expecting
Tada
I tried out some other syntaxes but got same result
<a th:href="#{{logourl}(logourl=~{text:test::text-login})}">Eureka</a>
You can get it to do exactly what you want by adding /text() to your fragment expression:
<a th:href="~{text:test::text-login/text()}">Tada</a>

Pass value of sessionStorage in javascript to <span> in html

I am developing an app with (JQM+cordova+backbone.js). I have 2 html pages. In the first page I have 1 textbox to input userID. so in the javascript file of the page i do
sessionStorage.userID=$("#userID").val();
in the second page i want to pass the value that i have stored in a tag. how do i do it? i only know if i want to use textbox instead i can do it by using
<input value="<%= sessionStorage.userID %>">
any help is much appreciated. Thanks
With JQuery, it whould be something like this:
//write from session storage to span
window.sessionStorage.setItem("userID", $("#spanID").html());
//write from session storage to span
$("#spanID").html(window.sessionStorage.getItem("userID"));
In Underscore template:
<span id="spanID"><%= window.sessionStorage.getItem("userID") %></span>
Are you using a Backbone plugin to handle session storage?

creating a string for a link in grails without g:link

In a tag like below:
<a data-url="/new/request/showText/${requestInstance.id}"> view text</a>
Is there a way to not hardcode the url like I have?
I tried using <g:link action="showText" id="${requestInstance.id}"> but that renders to an anchor tag.
What I'm doing might be find but I'm just curious if there is a better way to do this in grails?
You may use
${createLink(action:'myaction',params:[datasetId:dataset.id])}
for full control. It just returns something like http://myapp/myaction/123 and supportsall the params which g:link supports.
To be more specific:
<a data-url="${createLink(action:'showText',id: requestInstance.id)}"> view text</a>
should work.
You can use the createLink function inside of ${..}.
So in your case this would be:
<a data-url="${createLink(controller: 'yourController', action: 'yourAction', params:[param1: 'value1'])}"> view text</a>

Resources