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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:52:13+00:00 2026-05-23T14:52:13+00:00

I am using Ruby on Rails 3.0.7 and I am trying to implement an

  • 0

I am using Ruby on Rails 3.0.7 and I am trying to implement an act_as_article plugin for my application. What I would to do is run validation methods for the “acting as article class” inside that plugin (note: my plugin requires to create some database table columns in order to work – one of these is represented by the title attribute).

In my RoR application I have this code:

# vendor/plugins/article/lib/acts_as_article.rb
module Article
  extend ActiveSupport::Concern

  included do
    validates :title,  # Validation method
      :presence => true
  end

  module ClassMethods
    def acts_as_article
      send :include, InstanceMethods
    end
  end

  module InstanceMethods
    ...
  end
end

ActiveRecord::Base.send :include, Article


# app/models/review.rb
class Review
  acts_as_article

  ...
end

Using the above code the plugin works. However if I add some Record Association in the Review class like this:

class Review
  acts_as_article

  has_many :comments # Adding association

  ...
end

and in my ReviewsController I add the following, as well:

def create
  ...

  @article.comments.build(   # This is the code line 89
    :user_id => @user.id
  )

  if @article.save
    ...
  end
end

I get this error

NoMethodError (undefined method `title' for #<Comments:0x00000103abfb90>):
  app/controllers/articles_controller.rb:89:in `create'

Probably it happens because the validation run for all Review “associated” classes\models and the Comment class doesn’t have the title attribute. I think that because if inside the plugin code I comment out the validation method like this

module Article
  ...

  included do
    # validates :title,  # Validation
    #   :presence => true
  end

  ...
end

I don’t get errors anymore.

So, how can I solve this issue?

Note: I am not expert on creating plugin (this is my first time), so I ask implicitly also if I’m doing a good job for the plugin implementation…

  • 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-23T14:52:14+00:00Added an answer on May 23, 2026 at 2:52 pm

    You are including validates_presence_of :title in ActiveRecord::Base, and thus every active record model is picking it up. Instead, you should do:

    # vendor/plugins/article/lib/acts_as_article.rb
    module Article
      extend ActiveSupport::Concern
    
       module ClassMethods
        def acts_as_article
          validates :title,  # Add validation method here
            :presence => true
          send :include, InstanceMethods
        end
      end
    
      module InstanceMethods
        ...
      end
    end
    

    So that you only include the validation on ActiveRecord models that expect the validation to go through. Let me know if this solves your issue.

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

Sidebar

Related Questions

I am trying to build a free web application using ruby/rails It should be
I am using Ruby on Rails 3 and I am trying to implement a
I am trying to implement Superfeedr subscriptions using PubSubHubbub and Ruby on Rails. The
I am trying to implement a rails Recipe application from the site http://oreilly.com/ruby/archive/rails-revisited.html .
I am using Ruby on Rails 3 and I am trying to implement an
I am using Ruby on Rails 3 and and I am trying to implement
I am using Ruby on Rails 3.0.9 and I am trying to implement a
I am using Devise in my Ruby on Rails 3 application. I am trying
I'm trying to write an app using Ruby on Rails and I'm trying to
I'm trying to build a web service using Ruby on Rails. Users authenticate themselves

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.