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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:10:08+00:00 2026-06-15T08:10:08+00:00

Using Rails 3.2.9 I’m attempting to build a association using .build instead of .create

  • 0

Using Rails 3.2.9
I’m attempting to build a association using .build instead of .create but getting a password validation error that I can’t seem to find a workaround.

Review below:

The way I understand to save a item with a association that is built using .build you actually have to do the save in this case on the owner. If you do a save on the @item it just creates the item and not the association(meaning it doesn’t save to the DB until current_owner.save). when i do a save on the owner i hit a error due to password not meeting the validation requirements. Is there a way to bypass the validation when I do a save, due i need to implement a different solution for password, or just stop complaining and use .create instead of .build.

The below gives a password does not meet validation error

@item = current_owner.items.build(params[:item])
   if current_owner.save
       Do some other work with item
   end

I guess i could do the following(for some reason it seems dirty to me maybe not. Thoughts?)

 @item = current_owner.items.create(params[:item])
 if !@item.nil?
       Do some other work with item
 end

Table Setup:
owners:

  • id
  • name
  • encrypted_password
  • salt

items:

  • id
  • name

items_owners:

  • owner_id
  • item_id

Models:

class Item < ActiveRecord::Base
   attr_accessible :description, :name, :owner_ids

   has_many :items_owner
   has_many :owners, :through => :items_owner


end

class Owner < ActiveRecord::Base
   attr_accessor :password
   attr_accessible :name, :password, password_confirmation

   has_many :items_owner
   has_many :items, :through => :items_owner
   before_save :encrypt_password

   validates :password, :presence => true,
        :confirmation => true,
        :length => { :within => 6..40 }
end

class ItemsOwner < ActiveRecord::Base
   attr_accessible :owner_id, :item_id

   belongs_to :item
   belongs_to :owner
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-06-15T08:10:10+00:00Added an answer on June 15, 2026 at 8:10 am

    I didn’t understand very much your question. Hope this helps:

    @item = current_owner.items.build(params[:item])
    if @item.valid?
      # item is valid and ready to save to DB
    else
      # item is not valid.
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using Rails I'm trying to get an error message like The song field can't
Using Rails 2.3.8. I have added this in my controller: filter_parameter_logging :password, :password_confirmation But
Using Rails 3.1.3 with Ruby 1.9.3p0. I've discovered that by default, Rails does not
(Using Rails 3.1.3) I have an app that manages products. I import the products
Using Rails 2.3.11 , I'm creating a plugin for Redmine that add methods to
Using Rails 3.1.0 def create @practice = Practice.new(params[:practice]) respond_to do |format| if (current_user.practices <<
using rails 2.3.8. I'm getting this: [ [0] 0, [1] { name => Section,
Using: Rails 3.1.1 I am trying to create a search engine in my application
Using Rails 3.1.3. I have Accounts and Users. One Account can have many Users.
We're building an app, our first using Rails 3, and we're having to build

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.