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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:47:20+00:00 2026-05-28T02:47:20+00:00

I have a gem which is essentially just a bunch of ActiveRecord::Base classes in

  • 0

I have a gem which is essentially just a bunch of ActiveRecord::Base classes in the gems namespace. For all of them I get the same type of problem. I have the model…

module MyGem
  class User < ActiveRecord::Base
    ...
  end
end

Then in my app I have the routes…

resources :users

What gets screwed up is in the link_to…

<% @users.each do |user| %>
  <td><%= link_to 'Show', user %></td>
<% end %>

I get…

undefined method `my_gem_user_path' for #<#<Class:0x0000000305f728>:0x00000003055408>

I’ve tried various things in routes.rb, but I’m thinking the solution may be to configure the model/link_to to call user_path(user) instead of my_gem_user_path(user) by default. I just don’t know how, if at all possible, to do this.

Anybody know the best practice here?

  • 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-28T02:47:21+00:00Added an answer on May 28, 2026 at 2:47 am

    I think the best practice here is to namespace your routes. Your class is namespaced as MyGem::User. #link_to uses #polymorphic_path to query the class for its class name and then calls #underscorize on that class name to get the path, so it assumes that the path will be my_gem_user_path, not user_path. That means the resources call should be wrapped like so:

    namespace(:my_gem) do
      resources :users
    end
    

    Then, my_gem_user_path will resolve to the MyGem::UsersController. Make sure your controller is namespaced like that as well. If you don’t want the route to resolve to that controller, you can provide the controller name as an option to #resources.

    edit: That’s interesting, I didn’t think it would run into that problem. There may still be some configuration to fix that, so I wouldn’t mark this as solved yet. You can always replace the polymorphic_path (which is what is getting called when you use the resource-oriented path like above) with named routes. For example, instead of
    link_to “User”, user
    you can always explicitly use
    link_to “User”, my_gem_user_path
    When you use RESTful routes in your routes.rb file (with the #resources method), it provides you with those named routes.

    For the form_for, the syntax is slightly different:

    form_for(@user, @task)
    

    becomes

    form_for([@user, @task], :url => my_gem_user_my_gem_tasks_path(@user, @task), :method => :post)
    

    for a new form. For an edit form, it would be

    form_for(@task, :url => my_gem_user_my_gem_tasks_path(@user, @task), :method => :put)
    

    Does that make sense? Here’s a link to the documentation for form_for http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#method-i-form_for

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

Sidebar

Related Questions

I have a gem unpacked (youtube_g) in vendor/gems which works ok from Rails when
I have a engine style Rails plugin from which I can create a gem
I have an awesome trouble with Gem. After executing this command: rm -f /usr/local/lib/ruby/gems/1.9.1/cache/*
I have finally managed to get javan-whenever gem working on my site5 server, and
I have a gem, roundhouse , which is an application compiled with .NET (C#).
Say I have written a gem which makes lazy calls to the Google Distance
I have developed a gem which implements some algorithms that we'll use within a
I have a Rails 3 gem which has some rake tasks that should only
I've just installed the aruba gem which is an extension to cucumber. It allows
I need switching gem on which other gem relies. So in particular: i have

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.