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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T21:28:49+00:00 2026-05-18T21:28:49+00:00

I have a model called Notifications, which basically acts as a join table between

  • 0

I have a model called Notifications, which basically acts as a join table between Requests and Accommodations.

In my “create” method in my Requests controller, I have:

   # find associated accommodations, currently matching: location
    @accommodations = Accommodation.where('location' => :location)
    @accommodations.each do |accommodation|
      @notification = @request.notification.build('accommodation_id' => accommodation.id ).save
    end

Which doesn’t seem to be creating a new Notification record. What am I doing wrong here?

models/accommodation.rb

class Accommodation < ActiveRecord::Base
  validates_presence_of :title, :description, :thing, :location, :spaces, :price, :photo
  attr_accessible :photo_attributes, :title, :description, :thing, :location, :spaces, :price
  has_one :photo
  has_many :notifications
  belongs_to :user
  accepts_nested_attributes_for :photo, :allow_destroy => true
end

models/notification.rb

class Notification < ActiveRecord::Base
  attr_accessible :accommodation_id, :request_id
  has_one :request
end

models/request.rb

class Request < ActiveRecord::Base
  attr_accessible :firstname, :lastname, :email, :phone, :datestart, :dateend, :adults, :children, :location, :status
  validates_presence_of :firstname, :lastname, :email, :phone, :datestart, :dateend, :children, :adults, :location
  has_many :notifications
end
  • 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-18T21:28:49+00:00Added an answer on May 18, 2026 at 9:28 pm

    You don’t define @request or :location in your controller. Assuming it’s a Request object:

    @notifications = Array.new
    
    @accommodations = Accommodation.where('location' => :location)
    Accommodation.find_each(:conditions => { 'location' => :location }) do |a|
      notification = @request.notifications.create('accommodation_id' => a.id)
      @notifications << notifications
    end
    

    Just like @AnomalousThought said:

    There’s a lot to be said about the
    example provided, I think the
    implementation is entirely poor. But
    that’s not relative to the question of
    why the notification record isn’t saving.

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

Sidebar

Related Questions

I have a model called Details, and two controller methods new and create. New
I have a model called Contact which has_one guest like so. class Contact <
I have a model called Answer which has a ForeignKey relationship to another model
I have a model called Category which looks like this: class Category < ActiveRecord::Base
I have a model called shipments. I added some columns to the shipments table
I have a model called User, and a controller called ManagersController. Some users are
I have a model called Store with a table column named website and it
I have a model called Recipe which has 2 images that use carrierwave, so
I have a model called SimplePage in which I have this line: category =
I have a table called notifications in my DB and a table called notes.

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.