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 7445487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:50:17+00:00 2026-05-29T11:50:17+00:00

I have a method in controller – def undo_link view_context.link_to(undo, revert_version_path(@page.versions.scoped.last), :method => :post)

  • 0

I have a method in controller –

def undo_link
  view_context.link_to("undo", revert_version_path(@page.versions.scoped.last), :method => :post)
end

But when i call it in views with "#{undo_link}" . I get the
undefined local variable or method error .

what am i doing wrong ?

Update : Here the revert method in the controller

okay but then this is the revert method i got in the controller

def revert
  @version = Version.find(params[:id])
  if @version.reify
    @version.reify.save!
  else
    @version.item.destroy
  end
  link_name = params[:redo] == "true" ? "undo" : "redo"
  link = view_context.link_to(link_name, revert_version_path(@version.next, :redo => !params[:redo]), :method => :post)
  redirect_to :back, :notice => "Undid #{@version.event}. #{link}"
end
  • 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-05-29T11:50:24+00:00Added an answer on May 29, 2026 at 11:50 am

    As Dave Newton said in the comments (+1), this belongs in a helper.

    in helpers/pages_helper.rb:

    module PagesHelper
      def undo_link
        # ...define view_context here...
        view_context.link_to("undo", revert_version_path(@page.versions.scoped.last), :method => :post)
      end
    end
    

    Note that you will need to define view_context before this will work, either in the space indicated, passing it in as an argument, or by using an instance variable accessible to the view at the time the helper method is called.

    To call it in a view:

    <%= undo_link %>
    

    If you do this…

    "#{undo_link}"
    

    …you will get this:

     "<a href="/revert/version/path/...">undo</a>" # <= surrounded by quotes!
    

    which will not work.

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

Sidebar

Related Questions

I have a controller method with the following signature: [AcceptVerbs(HttpVerbs.Post)] public ActionResult UpdateValues(int id,
If you have a controller method like so: @expose(json) def artists(self, action=view,artist_id=None): artists=session.query(model.Artist).all() return
I have a controller method like such: def search = { def query =
Let's say I have a method at Controller named book($chapter,$page); where $chapter and $page
I have this method in a controller: def article_info if @article = Article.find_by_permalink(params[:permalink]) @title
I'm using Asp.Net-Mvc, I have this method in my controller: [AcceptVerbs(HttpVerbs.Post)] public ActionResult LinkAccount(string
I have method in my controller: def work_here @company = Company.find(params[:id]) current_user.work_apply(current_user, @company) redirect_to
I have a method in my controller that handles generic page requests, meant for
I have this method in my controller def mylovelyhaus @haus = Hause.find(params[:id]) end I
I currently have this method in a controller: def show property = Property.find(params[:id]) respond_to

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.