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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:47:09+00:00 2026-06-12T12:47:09+00:00

I have 2 models with an association. I want to setup a before_save in

  • 0

I have 2 models with an association. I want to setup a before_save in one model to modify the other. Here is what I have:

class Event < ActiveRecord::Base
  belongs_to :leads
end

class Lead < ActiveRecord::Base
  before_save  :update_event
  has_many :events, :dependent => :destroy
  accepts_nested_attributes_for :events, :reject_if => lambda { |a| a[:title].blank? }

  def update_event
    self.events.title = "Testing to set the event title"
  end
end

Ultimately Event has attributes such as title that will be set from various model associations within the system. In the example above, Leads is one of them. Leads will have a drop-down list of possible events so I would want to do something in a before_save whereas the selection in the drop-down ends up setting the event title. such as:

self.events.title = self.selected_event

The error I get is the following:

undefined method `title=' for #<ActiveRecord::Relation:0x007fed3229d610>

I’m clearly doing this wrong. I’d appreciate any help at all. I’m still searching for a solution and will update this myself if I figure it out.

Thank you!

  • 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-06-12T12:47:10+00:00Added an answer on June 12, 2026 at 12:47 pm

    You have multiple events per lead. So, in your situation you’d want to:

    before_save  :update_events
    
    def update_events
      events.each do |event|
        event.title = "Testing to set the event title"
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two dependent models with one to many association class Post < ActiveRecord::Base
I have two models with a one-to-one association. class User < ActiveRecord::Base has_one :setting
I have the following setup: Models: class Product < ActiveRecord::Base has_one :product_category attr_accessible :name,
I have three models : class LevelTwoArea < ActiveRecord::Base has_many :places, dependent: :restrict end
I have the following models, with their relevant associations: class User < ActiveRecord::Base has_many
I have 2 Models: # user.rb class User < ActiveRecord::Base has_one :profile, :dependent =>
I have 2 models that have a many-to-many association(an Event has many Products and
I have the following :has_many, :through association for my models: Group Model: has_many :group_users
I have a event model that has many invitations. Invitations are setup through checkboxes
I have two models, associated via an has_and_belongs_to_many association. I want to destroy the

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.