Customized error handling - ruby-on-rails

How can I achieve that the code below only will be executed if there is an HTML input-Tag? So that it won't be executed by the HTML label-Tag.
<div class=\"field_with_errors\">#{html_tag}</div>".html_safe
Thanks in advance!
Regards
Silvan

I'm not 100% sure what you're asking, but if you're asking what I think you are you could do something like:
<div class=\"field_with_errors\">#{html_tag}</div>".html_safe unless html_tag.nil?
If this isn't what you're looking for, could you please explain more about what you want to achieve?

Related

Problem with CLS due to <div id="content" class="site-content fixed">

Code makes a problem with the indicator CLS. I don't even understand in which direction I should "move" to solve it. Provide some ideas. Thank you!

Razor if statement inside HTML

Why I can do that:
#Code
Dim styleVisible As String = if(Model.IndicateurAchatPeriodique,"block","none")
End Code
<div id="#sectionDCAId" style="display:#styleVisible">...
but not that:
<div id="#sectionDCAId" style="display:#If(Model.IndicateurAchatPeriodique,"block","none")">
I just moved the if instruction inside the HTML but it throw an error. Why the compiler can't understand it?
I don't need solutions, just an explanation. Thanks
The compiler seems to have problems with inline VB.NET Ifs. Not sure if it is a bug or it just isn't quite that clever. I know you haven't asked for a solution, but if you put an extra set of brackets in to help it then it will probably work - as in #(If(Model.IndicateurAchatPeriodique,"block","none"))

How to say if something equals to a string in Sightly?

In Sightly, I want to have if statement as in below
if x == "Australia"
then
execute the html below
I am looking for some tutorial on how to do this or some example. This may not be worth asking here. However, please, may I have an example like that? I am stuck
I think you could do something like this:
<div data-sly-test="${x == 'Australia'}">
HTML about Australia
</div>
Here are some tutorials as well:
http://blogs.adobe.com/experiencedelivers/experience-management/sightly-intro-part-1/

Rails 4 WYSIWYG Bootsy not displaying formatting

I've just followed the install instructions at the the bootsy gem page and it all looks good until I save and look at the post's content.
This is what the output looks like in the view:
<h2>Header</h2><h3>Sub head:</h3><br><img alt="Thumb 1320236280147" src="/uploads/bootsy/image/1/1320236280147.jpg">
It seems that none of the html formatting is being rendered as it is being escaped by quoation marks or something like that - has anyone else had this problem? I haven't seen any issues on the github page or on SO to point me in the right direction.
I haven't done anything yet apart from follow the gem install instructions but maybe I missed something or am just making a stupid mistake.
If there's anything else you want to know please just ask.
Cheers
You need to have something like this, escape html:
<%= f.bootsy_area(:body, class: 'bg-code').html_safe %>
Sergio is correct but have the .html_safe on the output rather than the input.
For example, on a post index:
<%= post.body.html_safe %>
Hope this helps.
maybe use raw?
<%= raw(post.body) %>
You can also add to bootsy.rb
config.editor_options = {
html: true
.....
}
to enable you to toggle html in the bootsy editor .

How to get the total items in an array(array length) in dust.js

I can't seem to figure out(I'm pretty sure that I'm over thinking or not thinking here) a way to get the length of an array in the following example. Can anyone please help me, or direct me to a good tutorial. https://github.com/linkedin/dustjs/wiki/Dust-Tutorial has mentioned the {#size} helper but does not have any examples.
<ul total-tems={#items.length/}>
{#items}
<li class="item-{$idx}">{.title}</li>
{/items}
</ul>
Thank you in advance.
Yep, I was clearly overlooking. I was not including ( require('dustjs-helpers'); ) in order to use
<ul total-tems="{#size key=items /}">
Hope this will help others out as well.
I don't know if is it a new feature of dustjs but now you can simply use {items.length} to access the array length with no need of helpers.

Resources