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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:45:56+00:00 2026-06-10T04:45:56+00:00

I am n00b as rails is concerned. I am trying yo create a single

  • 0

I am n00b as rails is concerned. I am trying yo create a single multimodel form in my first rails3 project. Details are given below:

class Item < ActiveRecord::Base
  # attr_accessible :title, :body
  has_many :item_reviews, :dependent => :destroy
  accepts_nested_attributes_for :item_reviews
end

and

class ItemReview < ActiveRecord::Base
  # attr_accessible :title, :body
  belongs_to :item
end

So as clear, an item can have multiple reviews but when I am creating an item, I want at least 1 review for it. So I want to get item and first review in single form while item creation.

I am using following view:

<%provide(:title,'Create')%>
<h1> Add an Item review</h1>

<div class="row">
  <div class="span6 offset3">
    <%= form_for (@item) do |f| %>

      <%= f.label :name %>
      <%= f.text_field :name %>

      <% f.fields_for :item_reviews, @item.item_reviews do |ff| %>
        <%= ff.label :shop_address %>
        <%= ff.text_field :shop_address %>
      <% end %>

      <%= f.submit "Submit", class: "btn btn-large btn-primary" %>

    <% end %>

  </div>
</div>

<% f.fields_for :item_reviews, @item.item_reviews do |ff| %> will not work because there is not item_review associated with @item currently (@item = Item.new) Until I save @item, I can’t create new item_review. What should I do in that case.

I know one possibility is model independent form but can’t I use something above to make life easy.

PS: I am using bootstrap, just in case if that helps.

  • 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-10T04:45:57+00:00Added an answer on June 10, 2026 at 4:45 am

    There is some way to achieve an instance with item reviews. The key is to create an instance with some of nested instances without actual saving

    @item = Item.new
    @item.item_reviews.build
    

    and then in your form

    form_for @item do |f|
    ...
      f.fields_for :item_reviews do |ff|
    

    with this code an instance of review is present and you can render form

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

Sidebar

Related Questions

n00b here (first Android project). I have been given a custom video codec that
I'm a total n00b to c++ and am trying to make a simple form
I am a Clojure n00b trying to create some XML strings. My goal is
First of all i am a n00b. After 3 days of trying and research
I am a rails n00b. I want to use tinyMCE instead of a textarea
Disclaimer: I'm a rails n00b. I'm playing around with a simple helper function that
Totally n00b question, Im making my first ASP.NET website, with the added twist of
I'm really a n00b when it comes to regular expressions. I've been trying to
I'm a n00b in Rails and Rubymine IDE. The Rubymine Help says to To
I have a very n00b question about Rails. What are the variables and methods

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.