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

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
03407ea586d23291d4d2cc481a6b9948?d=identicon&s=25 Jörg Tillmann (scope)
on 2007-05-28 11: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,
etc.)

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|   %>

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

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

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


Does anybody have an idea of how to show the errors for the resource
objects?
(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.