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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T21:40:27+00:00 2026-06-07T21:40:27+00:00

I think I need a little help understanding how a simple Rails 3.2 one-to-one

  • 0

I think I need a little help understanding how a simple Rails 3.2 one-to-one association with a nested form works. I have a points form and when I visit it for the first time it loads with everything empty. And when I save everything looks good, it even has the right foreign key. Now, when I try to edit this record again by loading the form, the foreign key (results.pickem_id) gets nulled out and nothing loads in the form. It gets nulled the second @pickem.build_result is called. What do I need to do to allow editing of this form? I feel like I’m on the right track here so hopefully I’m missing something simple. I’ve included just the relavant code snippets but can provide more if need be.

Pickem.rb

  attr_accessible :result_attributes 
  has_one :result
  accepts_nested_attributes_for :result

Result.rb

belongs_to :pickem

pickems_controller.rb

  def update
    @pickem = Pickem.find params[:id]

    if @pickem.update_attributes params[:pickem]
      redirect_to pickem_path(@pickem), :notice => 'The pickem has been successfully updated.'
    else
      render "edit"
    end
  end

  def results #This is the results form
    @pickem = Pickem.find params[:id]
    @pickem.build_result #:pickem_id => params[:id]
  end

results.html.erb

<%= simple_form_for @pickem, :html => {:class => "form-horizontal"} do |f| %>
  <%= f.simple_fields_for :result do |r| %>
    <%= r.input :pickem_id, :input_html => { :value => params[:id] }, :as => 'hidden' %>
    <%= r.input :first_name, :label => 'First Name:' %>
  <% end %>
<% 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-07T21:40:30+00:00Added an answer on June 7, 2026 at 9:40 pm

    Try this. I feel it’s kinda messy but maybe it will work.

    @pickem.result = @pickem.build_result if @pickem.result.blank?
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need a little help writing a query. I have this data... vDir iNumber
Need a little help with what I'm sure is fairly easy jquery I have
I need a little help understanding how HTML forms work. It is my understanding
I need a little help understanding something. I am using the colorbox plugin to
I have started to study UML standard and would need little help with two
I need a little help with the fsockopen function. I have this PHP code:
I'm quite new to this Git thing and need a little help. I recently
I think I need something akin to a rails eager loaded query with a
I need little help regarding sharepoint solution set up in sharepoint. I created wspbuilder
I need some help to model this regular expression. I think it'll be easier

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.