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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T08:12:50+00:00 2026-06-05T08:12:50+00:00

I’m really new to both ruby on rails and programming. I am trying to

  • 0

I’m really new to both ruby on rails and programming. I am trying to develop an application but i am stucked now. I was watching http://railscasts.com/episodes/196-nested-model-form-part-1 to make nested model forms but i am having an error. My problem details are as follows;

I have employers model, and employers model has_many interviews, and interview model has_many customquestions. I’m trying to create a form through which i will collect info to create interview. Although i made all necessary assosications, when i submit the form it raises error saying that “Customquestions interview can’t be blank”. I am kinda sure that it is because of that i miss some code in interview controller. Below you can see my interview controller and the form template that i am using to submit info.

Interview Controller

class InterviewsController < ApplicationController
  before_filter :signed_in_employer

  def create
    @interview = current_employer.interviews.build(params[:interview])

    if @interview.save
      flash[:success] = "Interview created!"
      redirect_to @interview
    else
      render 'new'
    end
  end

  def destroy
  end

  def show
    @interview = Interview.find(params[:id])
  end

  def new
    @interview = Interview.new
      3.times do
    customquestion = @interview.customquestions.build
     end
  end
end

Form which i use to submit info:

<%= provide(:title, 'Create a new interview') %>
<h1>Create New Interview</h1>

<div class="row">
  <div class="span6 offset3">
    <%= form_for(@interview) do |f| %>
    <%= render 'shared/error_messages_interviews' %>

      <%= f.label :title, "Tıtle for Interview" %>
      <%= f.text_field :title %>

      <%= f.label :welcome_message, "Welcome Message for Candidates" %>
      <%= f.text_area :welcome_message, rows: 3 %>

      <%= f.fields_for :customquestions do |builder| %>
        <%= builder.label :content, "Question" %><br />
        <%= builder.text_area :content, :rows => 3 %>
      <% end %>
      <%= f.submit "Create Interview", class: "btn btn-large btn-primary" %>
    <% end %>
  </div>
</div>

In interview model, i used accepts_nested_attributes_for :customquestions

Interview Model

class Interview < ActiveRecord::Base
  attr_accessible :title, :welcome_message, :customquestions_attributes
  belongs_to :employer
  has_many :customquestions
  accepts_nested_attributes_for :customquestions

  validates :title, presence: true, length: { maximum: 150 }
  validates :welcome_message, presence: true, length: { maximum: 600 }
  validates :employer_id, presence: true
  default_scope order: 'interviews.created_at DESC'
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-05T08:12:51+00:00Added an answer on June 5, 2026 at 8:12 am

    The validation error gets raised in the customquestions model because (I assume) it validates :interview_id. The problem is that interview_id won’t get set until the parent object (Interview) is saved, but validations for customquestion are run before Interview is saved.

    You can let cusomtquestions know about this dependency by adding the option :inverse_of=> :customquestions to belongs_to :interview in the customquestions model.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I am trying to understand how to use SyndicationItem to display feed which is
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I am trying to render a haml file in a javascript response like so:

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.