I'm having some problems having html tags correctly loaded in my Rails 3.2 app, and have no clue why. I managed to get it working for one flash message, but I am not managing to do it with a confirmation message.
Any ideas ?
My pt.yml file extract :
buttons:
accept_terms: "Aceito os termos e condições"
save: "Gravar"
delete: "Apagar"
add_new_receipt: "+"
add_receipt_label: "Clique para adicionar novo recibo"
download_all_html: "Tem a certeza que deseja descarregar todos os ficheiros correspondentes à pesquisa? <br />
Esta operação pode demorar algum tempo, dependendo do número de ficheiros e da sua ligação à Internet "
my view code:
<%= link_to (t :download_all, scope: "pages.home.customers"), user_download_all_path(user_id:current_user.id, is_retailer: params[:controller]=='suppliers' ? true : false), method: :post, class: "btn btn-primary", confirm: t(:download_all_html, scope: "buttons") %>
In the end, My confirmation message shows the <br /> as is....
I believe I am following rails guidelines here, so any help would be appreciated to figure this one out.
Edit
I had already tried html_safe.
I have one other example that is working :
tags:
error_message_html: "O número %{message} ou não existe ou já foi mapeado.<br />
Por favor verifique que o número corresponde à empresa seleccionada "
and I invoke it inside a controller :
flash[:error] = t :error_message_html, scope: "forms.tags", message: params[:tag][:number]
Rails will escape the html contained in the translation
You can allow the html to be used with html_safe
<%= link_to (t :download_all, scope: "pages.home.customers").html_safe, user_download_all_path(user_id:current_user.id, is_retailer: params[:controller]=='suppliers' ? true : false), method: :post, class: "btn btn-primary", confirm: t(:download_all_html, scope: "buttons") %>
Related
Hy,
I don't know how to send email as html. I try every example that can i find but i don't know how to implement in my code. When it's arive in mail show all the html not only the the message. Please help me to implement send as html format in my code below. Thank you
def email(request):
campanii = Campanie.objects.order_by('-pub_date')
if request.method == 'POST':
form = EmailLoginForm(request.POST)
if form.is_valid():
email = form.cleaned_data['email'].lower()
user = UserVot.objects.filter(email=email).first()
if user is None: # daca userul nu exista cu acea adresa de email
messages.error(request, "adresa de email nu este corecta sau valida")
return render(request, 'loginvot/email.html', {'form' : form, 'campanii':campanii , 'error_message' : "adresa de email nu este corecta sau valida"} )
link += sesame.utils.get_query_string(user)
user.email_user(
subject="Link vot",
message="""\
<html >
<head>
<meta charset="UTF-8">
</head>
<body>
<p> Salutare, <h4>{{user.username}}</h4></p><br>
<p>Acceseaza link-ul de mai jos pentru a intra in sectiunea de vot "Ambasadorii Valorilor Profi"</p><br>
{{link}}
</body>
</html>
"""
)
return render(request, 'loginvot/email.html', {'campanii':campanii , 'error_succes' : "in maximum 1 minut vei primi pe adresa de email completata un link de accesare sesiune de vot"} )
context = {'form' : EmailLoginForm, 'campanii' : campanii}
return render(request, 'loginvot/email.html', context)
The solution turned out to be much simpler than I anticipated. I put the email message in a separate file (template_mail.html) and i use funtion render_to_string then in user.email_user I added html_message wich take that template_mail. This is how the code now looks and works.
template_mail = render_to_string ('loginvot/template_email.html', {'user' : user, 'link' : link } )
user.email_user(
subject='Link vot Ambasadorii valorilor Profi',
message=f"""some message""",
html_message = template_mail
)
Here is the code block:
<p>
Confira abaixo as perguntas frequentes. Se ainda assim
precisar, você poderá fazer #Html.ActionLink("contato nas unidades mais próximas",
"Index", "UnidadesEstados", new { target = "_blank" })
ou por e-mail.
</p>
If I remove the new { target = "_blank" } the page open correctly in the same tab.
I want to open this in a new tab, but when I execute, the URL that open its like:
http://localhost:61467/FAQ?**Length=15**
What I´m doing wrong?
I had included a null parameter between the others and this did the trick:
#Html.ActionLink("contato nas unidades mais próximas", "Index", "UnidadesEstados", null, new { target = "_blank" })
I stumbled on the following codepen and liked it a lot. I've never seen the HTML coded this way and I would like to understand what the author is doing here. There are no tags in the HTML pane but instead the author uses %. What does the % mean here and what is $base-color?
HTML
.container
.column
.til
%h1 Taller de Diseño Gráfico II
%p NARRATIVA VISUAL
.sub
%p TEMÁTICA
%h3 Patrimonio Cultural Inmaterial
.column.align-h
.circle-wrapper
- (1..5).each do |i|
%a{:class => "circle #{i}"}(href="#")#{i}
.column
.contain.text1
%h2 Evaluación 1
%p Definición del problema o necesidad
%p Metodología de la investigación
%p Aproximación al problema
%h4 20 de Agosto
.contain.text2
%h2 Evaluación 2
%p Fundamentos y Marco teórico
%p Búsqueda de información, recopilación de datos, estado del arte, otros
%h4 24 de Septiembre
.contain.text3
%h2 Evaluación 3
%p Definición de propuesta - Narrativa Visual
%p Contenidos conceptuales
%h4 15 de Octubre
.contain.text4
%h2 Evaluación 4
%p Proceso: Construcción de propuesta audiovisual
%h4 29 de Octubre
.contain.text5
%h2 Evaluación 5
%p Entrega final y presentación
%p Exposición en sala del proceso y audiovisual
%h4 26 de Noviembre
That is Haml code. In Haml, we write a tag by using the percent (%) sign and then the tag, for example: %strong, %div, %body, %html; any tag you want. Then, after the name of the tag is =, which tells Haml to evaluate Ruby code to the right and then print out the return value as the contents of the tag.
For example:
HTML:
<strong class="code" id="message">Hello, World!</strong>
Haml:
%strong{:class => "code", :id => "message"} Hello, World!
You can read more about Haml in the tutorial.
Can I use the link_to clickable for the whole div instead of only clicking on ¨Boeken naar afas¨?
Like at this moment if you click on ¨boeken naar afas¨ then the link_to does something.
I want to have it on the div instead of the text. So when you click on the div then it will be triggerd the ¨update_bookkeeping_claims_claim_manager_path(#claim_manager), method: 'post'¨
.col-sm-6.col-md-5.col-lg-3.item.ibox-title.import{:onclick => "move()"}
.box.boxBatenmanager
.boxInsite.boxTop
%i.fa.fa-exchange.icon.iconApps
%h3.name
Baten boeken naar #{#claim_manager.bookkeeping_name || 'AFAS'} do
%br/
%h4.description
Uw heeft #{#claim_manager.claims.scheduled_to_update_bookkeeping.count} baten
(#{#claim_manager.institution_claim_mutations.scheduled_to_update_bookkeeping.count} mutaties) aangemerkt om te boeken.
= link_to "Boeken naar AFAS", update_bookkeeping_claims_claim_manager_path(#claim_manager), method: 'post'
%br/
You can pass a block instead of a text label to the link_to helper, which allows you to nest your whole markup in the link:
= link_to update_bookkeeping_claims_claim_manager_path(#claim_manager), method: 'post' do
.col-sm-6.col-md-5.col-lg-3.item.ibox-title.import{:onclick => "move()"}
[...]
To be honest, this is my first time using asp.net web api and Razor.
I received an asp.net web api solution which uses itextSharp to generate a pdf.
The pdf is generated, but it is showing html tags that were sent with the content via jquery and JSON.
This is how it looks in PDF:
<div class="nf-filler-control-border"><div class="nf-filler-control-inner"><div class="ms-r
testate-field"><div
class="ExternalClassD88FE0C0B2A64B1797917A506C26ACA2"><div
class="ExternalClassAD6BB90065794E90B1097577B8697812">Aantal genodigden: 19</div><div
class="ExternalClassAD6BB90065794E90B1097577B8697812">Aantal aanwezig: 15</div><p
class="ExternalClassAD6BB90065794E90B1097577B8697812">Aantal ziek/verlof: 3</p><div
class="ExternalClassAD6BB90065794E90B1097577B8697812"><ol><li>Bij veiligheidsrondgang uitgevoerd op 02/04/13. Veel
gereedschap ligt niet op hun plaats, is onbeheerd achtergelaten, ligt in fietskarren, en zijn bovendien niet ingeschreven in
het register; kasten staan open, ladders niet afgesloten.</li><li>Persoonlijk werkgereedschap blijft gewoon liggen zelf
heeft men de dag erna verlof. = rommel.</li><li>Bij controle stekkers verleng kabels zien we dat de trekontlasting niet
correct gebruikt wordt en dat de insnijdingen te groot zijn. Zie foto's.</li>
<li>Alle communicatie (ziektebriefjes, KV,.....)met HR is nu naar Interleuvenlaan 27A - 3001 Herverlee
(achterzijde personeelsbadge)</li></ol></div></div></div></div></div>
this is the piece of code that displays data which is sent via jquery's ajax function: #Model.Description
And this is where the Razor engine parses the html template: return Razor.Parse(template, model);
Anyone has got any idea how to show the content properly inside the pdf without showing up the html tags on the document?
the html table shows fine, only the data displayed by #Model.Description does not show correctly.
this is the code:
private static string GetReport(ToolBoxMeeting tm)
{
var config = new TemplateServiceConfiguration
{
BaseTemplateType = typeof (HtmlTemplateBase<>)
};
using (new TemplateService(config))
{
string template = #"<html>
<body >
<table >
<tr>
<td'>Description</td>
<td>
#Model.Description
</td>
</tr>
</table>
</body>
</html>";
var model = tm;
return Razor.Parse(template, model);
}
}