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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:03:02+00:00 2026-06-18T09:03:02+00:00

I have a nested user registration form. I’d like to insert data for 3

  • 0

I have a nested user registration form. I’d like to insert data for 3 models. User, Store and Preference. The relationships are a User has_many :stores and has_one :preference.

The problem I’m having is that the hidden fields don’t show up in my view. Am I not using @user.restaurants.build and @user.build_preference correctly?

Here’s my models:

class User < ActiveRecord::Base
  attr_accessible :email, :full_name, :password, :password_confirmation
  has_secure_password

  validates_uniqueness_of :email
  validates_presence_of :full_name

  has_many :stores, :dependent => :destroy
  has_one :preference, :dependent => :destroy

  accepts_nested_attributes_for :stores
  accepts_nested_attributes_for :preference
end

class Store < ActiveRecord::Base
  attr_accessible  :name, :tagline, :address, :city, :postal, :state, :phone, :hours, :user_id

  belongs_to :user
end

class Preference < ActiveRecord::Base
  attr_accessible :background_fill, :background_position, :body_color, :body_font, :body_size, :heading_color, :heading_font, :heading_size, :layout, :link_color, :logo_color, :logo_size, :logo_font

  belongs_to :user
end

My UsersController:

class UsersController < ApplicationController

def new
  @user = User.new
  @user.stores.build
  @user.build_preference
end

My View:

<%= form_for @user do |f| %>
  <% if @user.errors.any? %>
  <div class="error_messages">
    <h2>There was an error!</h2>
    <ul>
      <% @user.errors.full_message.each do |message| %>
        <li><%= message %></li>
      <% end %>
    </ul>
  </div>
  <% end %>
  <%= f.label :full_name %>
  <%= f.text_field :full_name, :class => "target", :placeholder => "Your full name", :maxlength => "55", :autofocus => "autofocus" %>
  <%= f.label :email %>
  <%= f.email_field :email, :class => "target", :placeholder => "example@gmail.com", :maxlength => "55" %>
  <%= f.label :password %>
  <%= f.password_field :password, :class => "target", :placeholder => "Enter a password", :maxlength => "55" %>
  <%= f.label :password_confirmation, "Confirmation" %>
  <%= f.password_field :password_confirmation, :class => "target", :placeholder => "Enter your password again", :maxlength => "55" %>
  <% f.fields_for :stores do |builder| %>
    <%= builder.hidden_field :name, value: params[:name] %>
    <%= builder.hidden_field :tagline, value: params[:tagline] %>
    <%= builder.hidden_field :address, value: params[:address] %>
    <%= builder.hidden_field :city, value: params[:city] %>
    <%= builder.hidden_field :state, value: params[:state] %>
    <%= builder.hidden_field :postal, value: params[:postal] %>
    <%= builder.hidden_field :phone, value: params[:phone] %>
    <%= builder.hidden_field :hours, value: params[:hours] %>
  <% end %>
  <% f.fields_for :preference do |builder| %>
    <%= builder.hidden_field :layout, value: params[:layout] %>
    <%= builder.hidden_field :background_fill, value: params[:background_fill] %>
    <%= builder.hidden_field :background_position, value: params[:background_position] %>
  <% end %>
  <%= f.submit "Create an Account for Free", :class => "button cta" %>
<% end %>

Also, if it’s any help, I’m trying to follow this tutorial on Railscast: http://railscasts.com/episodes/196-nested-model-form-part-1

Thanks!

  • 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-18T09:03:03+00:00Added an answer on June 18, 2026 at 9:03 am
    <% f.fields_for :preference do |builder| %>
    

    This needs to be

    <%= f.fields_for :preference do |builder| %>
    

    The same goes for your other calls to f.fields_for.

    Source: The API

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

Sidebar

Related Questions

I have a User and Account models with has_one association and nested attributes. My
I have a nested form for has_many relationship using accepts_nested_attributes_for method. If I don't
I am using Nested User Controls.... Like: I have a 'A' User control that
I have a nested form in which I would like the form fields to
I have a nested user control which appears on every single page. It contains
I have a user control nested in a repeater. Inside my user control I
I have a user and nested profile class as follows: class User < ActiveRecord::Base
I have nested list of the following form: my_list = [['Some1', '2', '3.6', '4.5',
I have nested iframes and I would like to use onload function for the
I have an Account model that accepts nested attributes for a user model. An

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.