简体   繁体   English

如何准确地使用rails diffy gem比较另一个版本?

[英]How to accurately use the rails diffy gem to compare another version?

So I'm trying to compare recipes and then display the versions in a show. 因此,我尝试比较配方,然后在节目中显示版本。 The compare functionality and view works properly. 比较功能和视图正常工作。 I can see them both on the same page. 我可以在同一页面上看到它们。 However I want to use diffy to show just what's different between the two. 但是我想使用diffy来显示两者之间的区别。

I'm using the partial "show" to output the differences. 我正在使用部分“显示”来输出差异。 For sanity I want to build in this view diffy for the new "version". 为了理智起见,我想以此观点为新的“版本”建立差异。 So below feel free to ignore: render "show", food: @version. 因此,下面您可以忽略:渲染“显示”,食物:@version。

Right now in my compare(show) view I have the following: 现在在我的compare(show)视图中,我有以下内容:

  <div>
    <h1> Original recipe </h1>
    <%= render 'show', food: @original %>
  </div>
   <!-- Clone form  -->
  <div>
    <h1> Cloned recipe >> Version of the Original </h1>
    <%= render 'show', food: @version %>
    <div class='row mt'>
     <div class='col-sm-12'>
      <style><%= Diffy::CSS %></style>
       <div class='well diff'>
       <p>
        <strong>Name:</strong>
        <%= diff(food.recipe.name) %>
      </p>
    </div>
  </div>
</div>

I honestly can't think of what to put in the line below to compare the two: 老实说,我无法考虑在下面的行中将两者进行比较:

 <%= diff(food.recipe.name) %> 

I've tried doing variations on @original and @version separated by commas and even built out a food helper to no avail. 我尝试对@original和@version进行变体,并用逗号分隔,甚至建立了食物助手也无济于事。

My helper looks like: 我的助手看起来像:

   def diff(content1, content2)
    changes = Diffy::Diff.new(content1, content2,
                         include_plus_and_minus_in_html: true,
                         include_diff_info: true)
    changes.to_s.present? ? changes.to_s(:html).html_safe : 'No Changes'
  end

Thoughts on what I need to put in for diffy? 对我需要费解的想法有何看法?

花了一段时间,但:

 <%= diff(@version.recipe.name, @original.recipe.name) %>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM