Hi team,
I am trying to render custom HTML response for smart action. But i am getting some error.
This is my code snippet for the custom HTML response
render json: { html: <<EOF
<strong class="c-form__label--read c-clr-1-2">Errors</strong>
errors.map do |error|
<p class="c-clr-1-4 l-mb">#{error}</p>
end
EOF
}
I am getting the following error
Also i have tried to render simple HTML response
render json: { html: <<EOF
<strong class="c-form__label--read c-clr-1-2">There is an Error</strong>
EOF
}
Could you please help me out?
Thanks
Can you try to set the second EOF
at the start of the line ?
Hi @anon94532230,
It is working fine now.Thanks.
Now, i am not able to print the list of error messages stored in an array called ‘errors’
this is my code snippet
render json: { html: <<EOF
<strong class="c-form__label--read c-clr-1-2">Errors</strong>
errors.map do |error|
return <p class="c-clr-1-4 l-mb">errors</p>
end
EOF
}
This is what i got
Also i have tried to incorporate embedded ruby format as below
render json: { html: <<EOF
<strong class="c-form__label--read c-clr-1-2">Errors</strong>
<% errors.map do |error| %>
return <p class="c-clr-1-4 l-mb">error</p>
<% end %>
EOF
This is what i got
Is there a way to resolve this?
Or is there a way to incoporate erb templates in the custom html response?
thanks
Hello @ajithmani,
Coud you please try to:
- create an ERB template matching you snippet
- render it into a string variable
- pass this variable as the
html
field of the response
I think there may be an issue with the way your template is handled.
You can also try to print the generated html before calling render to assert everything is well.
1 Like