Vestal_versions 和 htmldiff 的回归问题

发布于 2024-08-30 15:16:29 字数 699 浏览 6 评论 0原文

我猜想可能有一种更简单的方法来完成我正在做的事情,以便代码不那么笨拙。

我无法理解如何使用 revert_to 方法...我想要一些可以同时调用两个不同版本的东西,但这似乎不是lvestal_versions 的工作方式。

这段代码有效,但我想知道我是否使一些事情变得比需要的更难,并且我想在深入研究之前找出答案。

@article = Article.find(params[:id])

if params[:versions]
  v = params[:versions].split(',')
  @article.revert_to(v.first.to_i)
  @content1 = @article.content
  @article.revert_to(v.last.to_i)
  @content2 = @article.content
end

如果您想知道,我将其与 HTMLDIFF 结合使用来获取版本更改。

<div id="content">
  <% if params[:versions] %>
    <%= Article.diff(@content1, @content2) %>
  <% else %>
    <%= @article.content %>
  <% end %>
</div>

I'm guessing there's probably an easier way to do what I'm doing so that the code is less unwieldy.

I had trouble understanding how to use the revert_to method... i wanted something where i could call up two different versions at the same time, but this doesn't seem to be the way that vestal_versions works.

This code works, but I'm wondering if I'm making something harder than it needs to be and I'd like to find out before I delve deeper.

@article = Article.find(params[:id])

if params[:versions]
  v = params[:versions].split(',')
  @article.revert_to(v.first.to_i)
  @content1 = @article.content
  @article.revert_to(v.last.to_i)
  @content2 = @article.content
end

In case you're wondering, I'm using this in conjunction with HTMLDIFF to get the version changes.

<div id="content">
  <% if params[:versions] %>
    <%= Article.diff(@content1, @content2) %>
  <% else %>
    <%= @article.content %>
  <% end %>
</div>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

多彩岁月 2024-09-06 15:16:29

我认为您正在寻找 Vestal_versions 提供的 changes_ Between 方法。

@article = Article.find(params[:id])

if params[:versions]
  v = params[:versions].split(',')
  @article_changes = @article.changes_between(v.first.to_i, v.last.to_i)
end

那么 @article_changes 是版本之间更改的哈希值。类似的东西

{"content" => ["first version content", "second version content"]}

可能会有所不同,具体取决于您的版本。

I think that you are looking for the changes_between method that vestal_versions provides.

@article = Article.find(params[:id])

if params[:versions]
  v = params[:versions].split(',')
  @article_changes = @article.changes_between(v.first.to_i, v.last.to_i)
end

then @article_changes is a hash of the changes between the versions. Something like

{"content" => ["first version content", "second version content"]}

Maybe different depending on what you have versioned.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文