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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T15:03:03+00:00 2026-06-16T15:03:03+00:00

class Article < ActiveRecord::Base attr_accessible :console, :ean, :title, :title_spaceless has_many :dealers, :through => :units

  • 0
class Article < ActiveRecord::Base
  attr_accessible :console, :ean, :title, :title_spaceless
  has_many :dealers, :through => :units
end

class Dealer < ActiveRecord::Base
  attr_accessible :adress, :name, :website
  has_many :articles, :through => :units
  validates :name, :uniqueness => { :case_sensitive => false }
end

class Unit < ActiveRecord::Base
  attr_accessible :article_id, :dealer_id, :note, :price
  belongs_to :article
  belongs_to :unit 
end

How do I create an Dealer, an Article and a Unit at the same time?

First thing I tried was something like this, but it seams to be totally wrong.

@dealer = Dealer.find_or_create_by_name("Surugaya")
@dealer.article.create(:title => game.content, :title_spaceless => game.content.delete(' '), :console => "SNES").unit.create(:article_id => @dealer.article.article_id, :units_id => @dealer.article.unit_id, :price => game.price) 
  • 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-16T15:03:04+00:00Added an answer on June 16, 2026 at 3:03 pm

    Firstly, you’re missing a units association on your Article class. You’ll need to fix that:

    has_many :units
    

    By ‘at the same time’, I’m assuming you mean in the same database transaction. You can try this:

    Dealer.transaction do
      @dealer = Dealer.find_or_create_by_name("Surugaya")
      @article = @dealer.articles.create!(
          :title => game.content, 
          :title_spaceless => game.content.delete(' '), 
          :console => "SNES"
      )
      @unit = @article.units.create!(:price => game.price)
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given this has_many, :through scenario: article.rb class Article < ActiveRecord::Base attr_accessible :body, :issue, :name,
For example: class Post < ActiveRecord::Base belongs_to :article end class Article < ActiveRecord::Base has_many
class Article < ActiveRecord::Base has_many :comments end class Comment < ActiveRecord::Base belongs_to :article validates_presence_of
class Article < ActiveRecord::Base has_many :comments belongs_to :category end Is there a class method
Here's my code: Models: class Article < ActiveRecord::Base attr_accessible :title, :author, :content, :imageable_attributes has_one
Consider this: class User < ActiveRecord::Base # name, email, password end class Article <
Given this relationship: class Doc < ActiveRecord::Base has_and_belongs_to_many :articles end and class Article <
I've two models class Article < ActiveRecord::Base has_one :review end class Review < ActiveRecord::Base
I have two models like this: class Topic < ActiveRecord::Base has_many :articles end class
Let's say I have a model called Article: class Article < ActiveRecord::Base end And

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.