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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:29:50+00:00 2026-05-27T03:29:50+00:00

I’ve got a simple nested form working in my rails3 application. I’m trying to

  • 0

I’ve got a simple nested form working in my rails3 application. I’m trying to work out how to save a value from the parent model into the child when saving.

class Radcheck < ActiveRecord::Base
  set_table_name 'radcheck'
  attr_accessible :attribute_name, :username, :value, :op
  belongs_to :raduser  
end

class Raduser < ActiveRecord::Base
  has_many :radcheck, :dependent => :destroy
  accepts_nested_attributes_for :radcheck  
end

And my form:

<%= form_for @raduser do |f| %>  
  <p>  
    <%= f.label :username %><br />  
    <%= f.text_field :username %>  
  </p>  
  <%= f.fields_for :radcheck do |builder| %>  
  <li>  
    <%= builder.label :attribute_name %><%= builder.text_field :attribute_name %>  

  </li>  
  <% end %>  
  <p><%= f.submit "Submit" %></p>  
<% end %>

What I want to do is save the Raduser.username value in to the radcheck table on save. For each record.

I’ve tried putting something in the controller but that wasn’t really working for us.

— Update —

In my radcheck controller, I’ve tried this (as a test) but the values don’t save.

def create
      @radcheck = Radcheck.new(params[:radcheck])
      @radcheck.username = '123'
      respond_to do |format|
        if @radcheck.save

          format.html { redirect_to @radcheck, notice: 'Radcheck was successfully created.' }
          format.json { render json: @radcheck, status: :created, radcheck: @radcheck }
        else
          format.html { render action: "new" }
          format.json { render json: @radcheck.errors, status: :unprocessable_entity }
        end
      end
    end

Have also tried in radusers but that gave error.

  • 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-27T03:29:50+00:00Added an answer on May 27, 2026 at 3:29 am

    It looks like the controller code you posted is for the Radcheck controller, correct? If so, the form you have also posted will be using the create action of the RaduserController class, not the one from RadcheckController. This would explain why you aren’t seeing the username ‘123’ in the radcheck rows.

    If the username field is the same between parent and child, a common way to sync these two up would be with an observer or a before_save callback. I’ll outline the before_save method below:

    class Radcheck < ActiveRecord::Base
      set_table_name 'radcheck'
      attr_accessible :attribute_name, :username, :value, :op
      belongs_to :raduser
    
      before_save :sync_usernames
    
    private
    
      def sync_usernames
        self.username = self.raduser.username
      end
    end
    

    I’ve tested this with Rails 3.1 and it works; however, I know I have run into issues accessing parent models within a child model in previous versions of Rails. In those cases, I had to put the before_save action on the parent model, and have it iterate over each child, setting the appropriate attributes that way.

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

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have just tried to save a simple *.rtf file with some websites and
I have a text area in my form which accepts all possible characters from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I've got a string that has curly quotes in it. I'd like to replace
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Seemingly simple, but I cannot find anything relevant on the web. What is 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.