i am using vestal_version in my rails app. And i am wondering how do I show the previous versions edit links with respect to what is at the above entry. My html.erb code is
<tbody>
<% @page.versions.each do |page| %>
<tr class="odd">
<td><input type="checkbox" /></td>
<td> </td>
<td><%= page.created_at%></td>
<td>
<% if params[:version] %>
<%= link_to "Previous Version", :version => @page.version-1 %>
<%end%>
</td>
</tr>
</div>
<% end %>
and in controller i have @page.revert_to(params[:version].to_i) if params[:version]
I have attached a link to the screenshot. And if closely observe. the ?version=5 for all the entries. I want to have all the versions that is 1,2,3,4 and 5. How do i do that ?
Update : Image is hyper linked in the comment. I am not allowed add an image as of now.
Use
pageinstead of@page.pagechanges with each iteration, while@pagestays the same.EDIT:
Since
@page.versions.eachiterates a collection of versions, it should be passed into the block asversion, notpage.This method only shows the version. Actually reverting a version should be done via POST, since you are making changes to the database.
Reverting negates changes, it does not discard changes. If
pageis at version 4, and you revert to version 2, it does not delete versions 3 and 4. The version number will revert to 2, but will count as a version itself.#revert_todoes the reversion but does not save. To revert and save, use#revert_to!To properly use
#revert_to!, you need to put it in a controller action.Example, in your
pagescontroller:In your
routes.rb:then in your view: