Models/tables with relationships and forms

Hi, I’m just starting out writing a RoR application, and I have a
couple of questions…

Lets say I have a model
class Questionnaire < ActiveRecord::Base
has_many :categories
end

I’ve understood that one can reference a variable from the model/table
in a form using e.g.
<%= text_field ‘questionnaire’, ‘title’ %>

But what if I want to do the same with the related model Category?
Using
<%= text_field(‘category’, ‘caption’) %>
does not give any information about which questionnaire the category
belongs to. Are there any neat tricks to do this within the framework,
lets say something like
<%= text_field(‘questionnaire_category_123’, ‘caption’) %>
or must I write some custom code to do this?

And what about validations: using validates_* now only reports that
something is wrong within Categories when i try to do
“some_questionnaire.save”, but does not give me any specific
information about what failed to validate. How can I get that sort of
information?

Any help is greatly appreciated!

Best,
Arnfinn

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs