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

  • Home
  • SEARCH
  • 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 1838178
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T06:26:43+00:00 2026-05-17T06:26:43+00:00

This seems like a noob question, but the simple answer is eluding me. I

  • 0

This seems like a noob question, but the simple answer is eluding me. I need to call link_to in an ActionController method to spit out an HTML link. ActionView::Helpers::UrlHelper.link_to calls url_for, but this calls the AV module’s version instead of the controller’s. I managed to coerce this into doing what I intended by putting

  #FIXME there must be a better way to mixin link_to
  alias_method :self_url_for, :url_for
  include ActionView::Helpers::UrlHelper
  alias_method :url_for, :self_url_for

in the controller. But, I’m still not sure why it works exactly. Could someone please explain the method scope and hiding that’s happening here? What’s a better way to mix in link_to (or generally, to include only some methods from a module) so I can call it in the controller (generating a flash string with a link is the use case.)

Please, no lectures about MVC–if anything, link_to should be in a module separate from url_for. Judging from the amount of noise on this, lots of people run into this seemingly trivial snag and end up wasting an hour doing it the “Rails way” when really what is wanted is a one minute hack to make my app work now. Is there a “Rails way” to do this with helpers perhaps? Or a better ruby way?

  • 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-17T06:26:43+00:00Added an answer on May 17, 2026 at 6:26 am

    This doesn’t really answer your question but there is an easier way

    For Rails 5, use the helpers proxy

    helpers.link_to '...', '...'
    

    For Rails 3 and 4, since you are using the helper from a controller you can use the view_context

    # in the controller code
    view_context.link_to '...', '...'
    
    # instead of using your mixin code 
    link_to '...', '...'
    

    For Rails 2, since you are using the helper from a controller you can actually access the @template member variable of the controller, the @template is the view and already has the UrlHelper mixed in

    # in the controller code
    @template.link_to '...', '...'
    
    # instead of using your mixin code 
    link_to '...', '...'
    

    if you need to use the urlhelper from code other than the controller, your solution is probably the way to go

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

Sidebar

Related Questions

This seems like a simple question, but I can't find it with the Stack
This seems like such a simple question, but I'm having such difficulty with it.
this seems like a really simple Question...but behold :) Geek name:string Laser geek_id:integer, power:integer
This seems like a pretty softball question, but I always have a hard time
This seems like a silly question but I would really like your comments and
This seems like perhaps a naive question, but I got into a discussion with
this seems like very simple maths but somehow, my brain cant think ... i
This seems like a very simple and a very common problem. The simplest example
This seems like such a trivial problem, but I can't seem to pin how
How can I construct my ajaxSend call, this seems like the place to put

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.