Forum: Ruby on Rails validation for items in a 1 2 many

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.
James M. (Guest)
on 2006-03-04 14:43
I am populating a table skills which relate to a table cv in a 1 cv to
many skills relationship...

I populate the skills as below;

  def new
    @session[:cv_id] = params[:id]
    @skill = Skill.new
  end

  def create
    @cv = Cv.find(@session[:cv_id])
    @cv.skills << Skill.new(params[:skill])
    if @cv.save
      flash[:notice] = 'Skill was successfully created.'
      redirect_to :action => 'show', :controller => 'cv_admin', :id =>
@cv
    else
      render :action => 'new'
    end
  end


Having got the create method to populate correctly, the validation
helpers in the skills model have stopped working they trap errors on the
form and send the form back, but the;

<%= error_messages_for 'skill' %>

no longer works as it just has errors associated with cv rather than
skill...

any idea how to make the standard helpers work in this 1 to many world?

Thanks
James M. (Guest)
on 2006-03-05 03:19
James McCarthy wrote:
please ignore... newbie error!
This topic is locked and can not be replied to.