First, what you need to do first, to submit a form containing multiple models, is to accept nested attributes.
In the page.rb file, put:
class Page < ActiveRecord::Base has_many :blocks has_many :block_contents, :through => :blocks accepts_nested_attributes_for :field_contents
Secondly, in the view - you must indicate which fields for this model are used using the fields 'fields_for' So inside form_for @page, you must put:
<%= f.fields_for :field_contents do |b| %>
Since: field_contents is the only object that will be updated with @page. So the form element in it looks like this:
<% @page.blocks.each do |block| %> <% block.block_contents.each do |block_content| %> <% field_group.fields.each do |field| %> <%= form_for @page do |f| %> <%= f.input :any attribute %> <%= f.fields_for :field_contents do |b| %> <%= b.text_field :content %> <%= f.fields_for :block_contents do |b| %> <%= b.hidden_field :block_content, value: "#{@block_content.id}"%> <% end %> <% end %> <% end %> <% end %> <% end %> <% end %>
Since I learned that you can already access @ page.field_content, you do not need to touch anything in the controller, as it automatically updates the record based on the existing relationship.
So, now that all the models are presented in one request, you indicated that error messages should be displayed inside the view after the check has been performed. And this is the easy part.
From what I see, you are currently checking for :content
.
In your opinion: just put the HTML tag or the rails content tag
<p class= "error"><%= "Your error message"if @field_content.errors[:content].present? %></p>
Let me know if you have further questions.