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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:44:41+00:00 2026-05-16T17:44:41+00:00

This question is related to extending class methods in Ruby, perhaps more specifically in

  • 0

This question is related to extending class methods in Ruby, perhaps more specifically in the way that permalink_fu does so.

It appears that has_permalink on a model will not be available in a derived model. Certainly I would expect anything defined in a class to be inherited by its derived classes.

class MyScope::MyClass < ActiveRecord::Base
  unloadable
  self.abstract_class = true
  has_permalink :name
end

class MyClass < MyScope::MyClass
  unloadable
  #has_permalink :name # This seems to be required
end

Is there something in the way permalink_fu mixes itself in that causes this issue?

I’m using the permalink-v.1.0.0 gem http://github.com/goncalossilva/permalink_fu

  • 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-16T17:44:42+00:00Added an answer on May 16, 2026 at 5:44 pm

    After investigating this, I can now see that the problem is related to how permalink_fu verifies it it should create a permalink or not. It verifies this by checking if the permalink_field of the class is blank or not.

    What’s the permalink_field? When you do

    class Parent < ActiveRecord::Base
      has_permalink :name
    end
    
    class Child < Parent
    end
    

    you can access the permalink by writing Parent.new.permalink or Child.new.permalink. This method name can be changed by writing

    class Parent < ActiveRecord::Base
      has_permalink :name 'custom_permalink_name'
    end
    

    If so, the permalink will be accessible by writing Parent.new.custom_permalink_name (or Child.new.custom_permalink_name).

    What’s the problem with this? The permalink_field accessor methods are defined on Parent‘s metaclass:

    class << self
      attr_accessor :permalink_field
    end
    

    When you run the has_permalink method, it calls Parent.permalink_field = 'permalink'.

    The problem is that although the permalink_field method is available on all subclasses, its value is stored on the class it was called. This means that the value is not propagated to the subclasses.

    So, as the permalink_field is stored on the Parent class, the Child does not inherit the value, although it inherits the accessor methods. As Child.permalink_field is blank, the should_create_permalink? returns false, and Child.create :name => 'something' does not create a permalink.

    A possible solution would be to replace the attr_acessors on the metaclass with cattr_accessors on the class (lines 57 to 61 on the permalink_fu.rb file).

    Replace

    class << base
      attr_accessor :permalink_options
      attr_accessor :permalink_attributes
      attr_accessor :permalink_field
    end
    

    with

    base.cattr_accessor :permalink_options
    base.cattr_accessor :permalink_attributes
    base.cattr_accessor :permalink_field
    

    Note that this will invalidate any possible customization on the subclass. You will no longer be able to specify different options for the subclasses, as these three attributes are shared by Parent and all its subclasses (and subsubclasses).

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

Sidebar

Related Questions

This question is related to (but perhaps not quite the same as): Does Django
(This question is related to another one , but different enough that I think
This question is related to another question that I posted on SO earlier How
This question is related to my previous question Link The method bellow does excatly
Please note this question related to performance only. Lets skip design guidelines, philosophy, compatibility,
This question is related to another question I wrote: Trouble using DOTNET from PHP.
This question is related to the one I asked here . I'm trying to
This question is related to another question, where I wanted to define a custom
This question is related to my previous post Image Processing Algorithm in Matlab in
This question is related to this SO post Rather than using a recursive CTE

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.