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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:45:17+00:00 2026-05-27T17:45:17+00:00

i´m a newbie to rails and have a problem with my associated object not

  • 0

i´m a newbie to rails and have a problem with my associated object not being saved. I think I did everything the way it should be done and I can´t figure out, why it isn´t working. So thanks in advance for everyone who can help me get a little closer to solving this problem.
These are my models :

class Examdate < ActiveRecord::Base
  belongs_to :exam
  attr_accessible :date, :exam_id
end
class Exam < ActiveRecord::Base
  attr_accessible :title, :prof_id, :deadline
  belongs_to :prof
  has_many :examdates, :dependent => :destroy
  accepts_nested_attributes_for :examdates
end

In my exams_controller I have this:

def new
    @exam = Exam.new
    3.times{@exam.examdates.build()}
end
def create
    @exam = Exam.new(params[:exam])
    respond_to do |format|
      if @exam.save 
      ....

Now in my view I have the semantic_fields_for method, I also tried it with normal fields_for and got the same result:

<%= semantic_form_for @exam do |f| %>
<% if @exam.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@exam.errors.count, "error") %> prohibited this post from being saved:</h2>

      <ul>
      <% @exam.errors.full_messages.each do |msg| %>
        <li><%= msg %></li>
      <% end %>
      </ul>
    </div>
<% end %>   
<%= f.inputs do%>
<%= f.input :title%>
<%= f.input :prof%> 
<%= f.input :deadline, :start_year => Time.now.year, :label => "Anmeldefrist"%>
 <% end %>  
<%= f.semantic_fields_for :examdates do |builder|%>
    <%= render "examdates_fields", :f => builder %>
<% end %>
 <%= f.buttons do %>
  <%= f.commit_button "Speichern"%>
<% end %> 
<% end %>

In the partial is this, will later be extended

<%= f.inputs :date%>

Now I get the form with the correct three date fields and I can save the Exam itself correctly. When I look at params[:exam][:examdates_attributes] the dates are there:

{"0"=>{"date(1i)"=>"2006", "date(2i)"=>"1", "date(3i)"=>"1"},
 "1"=>{"date(1i)"=>"2006", "date(2i)"=>"1", "date(3i)"=>"1"},
 "2"=>{"date(1i)"=>"2006", "date(2i)"=>"1", "date(3i)"=>"1"}}

But when I put Exam.find(1).exdates in my rails Console, I get []. I really don´t have any idea what I did wrong, so every little tip is very appreciated:)

  • 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-27T17:45:18+00:00Added an answer on May 27, 2026 at 5:45 pm

    Since you are using attr_accessible in your Exam model, I think you’ll have to include :examdates_attributes in that list. Otherwise, mass assignment to the nested model will not be allowed.

    class Exam < ActiveRecord::Base
      attr_accessible :title, :prof_id, :deadline, :examdates_attributes
      ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a newbie to rails, and I have researched a whole day. I think
Just another Rails newbie with a problem. I have some Javascript (dynamic) in a
Rails newbie here. If I have a model and a table associated with it,
A bit of a newbie question on rails associations. I have a Bug model,
I am a newbie to Ruby on Rails . I have started working on
please help a newbie in Rails :) I have protect_from_forgery call (which is given
A rails newbie here I have 2 actions in my controller 1) index 2)
Rails newbie here. I have a list of items which can have a status
Hi (huge Rails newbie here), I have the following models: class Shop < ActiveRecord::Base
Complete rails newbie trying to get started. I have two classes, Ingredient, and Unit.

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.