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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:59:57+00:00 2026-05-14T05:59:57+00:00

My app should render html, to answer when a user clicks ajax-link. My controller:

  • 0

My app should render html, to answer when a user clicks ajax-link.

My controller:

def create_user
  @user = User.new(params)
  if @user.save
    status = 'success'
    link = link_to_profile(@user) #it's my custom helper in Application_Helper.rb
  else
    status = 'error'
    link = nil
  end

  render :json => {:status => status, :link => link}
end

My helper:

  def link_to_profile(user)
    link = link_to(user.login, {:controller => "users", :action => "profile", :id => user.login}, :class => "profile-link")
    return(image_tag("/images/users/profile.png") + " " + link)
  end

I have tried such methods:

ApplicationController.helpers.link_to_profile(@user)
# It raises: NoMethodError (undefined method `url_for' for nil:NilClass)

and:

class Helper
  include Singleton
  include ActionView::Helpers::TextHelper
  include ActionView::Helpers::UrlHelper
  include ApplicationHelper
end
def help
  Helper.instance    
end

help.link_to_profile(@user)
# It also raises: NoMethodError (undefined method `url_for' for nil:NilClass)

In addition, yes, I KNOW about :helper_method, and it works, but i don’t want to overload my ApplicationController with a plenty of that methods

  • 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-14T05:59:57+00:00Added an answer on May 14, 2026 at 5:59 am

    Oki. Let’s recap. You want access to certaint functions/methods, but you don’t want those methods to be attached to current object.

    So you want to make a proxy object, that will proxy/delegate to those methods.

    class Helper
      class << self
       #include Singleton - no need to do this, class objects are singletons
       include ApplicationHelper
       include ActionView::Helpers::TextHelper
       include ActionView::Helpers::UrlHelper
       include ApplicationHelper
      end
    end
    

    And, in controller:

    class UserController < ApplicationController
      def your_method
        Helper.link_to_profile
      end
    end
    

    The main disadvantage to this approach is that from the helper functions you won’t have access to controller context (EG you won’t have access to params, session, etc)

    A compromise would be to declare those functions as private in the helper module, therefore, when you will include the module, they will also be private in the controller class.

    module ApplicationHelper
      private
      def link_to_profile
      end
    end
    
    class UserController < ApplicationController
      include ApplicationHelper
    end
    

    , as Damien pointed out.

    Update: The reason why you get the ‘url_for’ error is that you do not have access to controller’s context, as stated above. You could force passing the controller as a parameter(Java-style 😉 ) like:

    Helper.link_to_profile(user, :controller => self)
    

    and then, in your helper:

    def link_to_profile(user, options)
      options[:controller].url_for(...)
    end
    

    or event a bigger hack, presented here. However, i would reccomend the solution with making methods private and including them in the controller.

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

Sidebar

Ask A Question

Stats

  • Questions 424k
  • Answers 424k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Just use self.navigationController. May 15, 2026 at 11:49 am
  • Editorial Team
    Editorial Team added an answer Since you don't have to deal with days, the algorithm… May 15, 2026 at 11:49 am
  • Editorial Team
    Editorial Team added an answer The best way is to abstract the access of m_iR… May 15, 2026 at 11:49 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.