Forum: Ruby on Rails Polymorphic Associations - Error-Handling?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Jörg T. (Guest)
on 2007-05-28 13:17
Hey there,

I have used polymorphic associations to model different types of
questions (multiple choice, simple text, etc.) I want to allow users to
create these questions and chose a type to enter the specific data ( max
text length for text fields, options for multiple choice questions,

How do I get to the errors of these question type subclasses?

This way, see 2. line, it does not work..

<%= error_messages_for :question %>
<%= error_messages_for :question.resource %>

<% form_for :question, @question, :url => {:action => :new, :survey =>
@survey} do |form|   %>

    <label for="text"><%= _( "Question" ) %></label>
    <%= form.text_field :text %>

<%  fields_for :comment_question, @question.resource do
|comment_question| %>
    <label for="size"><%= _( "Size" ) %></label>
    <%= :size,
CommentQuestion::COMMENT_SIZE_OPTIONS %>
<%  end %>

    <%= submit_tag _( "Create Question" ) %>
<% end %>

Does anybody have an idea of how to show the errors for the resource
(In this example, the CommmentQuestion of course has a
validates_inclusion_of :size in it!)
This topic is locked and can not be replied to.