Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8692311
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:17:29+00:00 2026-06-13T00:17:29+00:00

I am replacing some Spree core template code with Deface and it all works

  • 0

I am replacing some Spree core template code with Deface and it all works well until I try to make it a bit more custom.

Deface::Override.new(
    :virtual_path => "spree/shared/_products",
    :replace => "span.price",
    :text => "<%= link_to truncateproduct.display_price + '<span class=\"purchase-suggestion\">BUY NOW</span>', :length => 20), product, :class => 'price selling', :itemprop => \"price\", :title => product.name + ': ' + product.display_price %>",
    :name => "product_price"
)

Above I am aiming to make the price text a link, and also include a ‘BUY NOW’ text wrapped in a span for individual styling purpose.

This renders this way:
$15.99<span class="purchase-suggestion">BUY NOW</span>

How can I make Deface evaluate the HTML instead of writing the string?

I have tried doing this in two steps by making two different Deface files, one where I swap the span for the link, and another where I add the span to :insert_bottom. It seems to me it is not possible to use Deface to change the same element twice – is this correct?


Solution
Thanks for answer and conversation in channel. This is the solution:

Deface::Override.new(
    :virtual_path => "spree/shared/_products",
    :replace => "span.price",
    :text => "<%=
                  link_to ('<span>' + product.display_price + '</span> <span class=\"purchase-suggestion\">BUY NOW</span>').html_safe, product,
                  :class => 'price selling',
                  :itemprop => 'price',
                  :title => product.name + ': ' + product.display_price
              %>",
    :name => "product_price"
)

.truncate was used for no reason, .html_safe did the job.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T00:17:30+00:00Added an answer on June 13, 2026 at 12:17 am

    Your issue here is with truncate. The result is not marked as HTML-safe, so will be subject to the default escaping when used in views, unless wrapped by raw(). Care should be taken if text contains HTML tags or entities, because truncation may produce invalid HTML (such as unbalanced or incomplete tags).

    http://apidock.com/rails/ActionView/Helpers/TextHelper/truncate

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am replacing some deprecated Javadoc annotation in code I am unfamiliar with. Most
I need some comparing and replacing code in PHP Our mission is to empower
I’m trying to understand code from http://www.yesodweb.com/book/conduits . After some fixes (like replacing Resource
So I was tasked at replacing some dummy code that our project requires for
I've following function for getting HTML template from server and replacing some tags $.ajax({
I was trying to cut thread contention in my code by replacing some synchronized
I am cleaning up some of our network-code and while replacing various integer types
I have just optimised some Ruby code that was in a controller method, replacing
I am replacing all occurances of \n with the <BR> tag, but for some
I'm replacing some code in an old application, and instead of getting the node

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.