嵌套表单验证

时间:2012-03-02 16:54:07

标签: ruby-on-rails ruby-on-rails-3 validation

模特:

Names - belongs_to People
People - has_many names

查看:

= form_for @people do |f|
  .blkfr
    = f.fields_for :names do |f_name|
        = f_name.text_field :name

控制器:

# People controller
def update
  #find people
  if @people.update_attributes(params[:people])
    flash[:notice] = "Successfully updated people"
    respond_with @people
  else
    flash[:alert] = "There was an error updating people"
    respond_with @people
  end
end

错误:

Template is missing

Missing template people/edit, application/edit blah blah

我没有人物编辑方法的模板。我目前正在打的路线是:

.../people/1/names

我的问题是如何告诉rails跳回到同一个视图(名称索引页面),但是返回@people对象的错误而没有收到该错误?

1 个答案:

答案 0 :(得分:1)

如果您没有编辑模板,请指定要在控制器中呈现的模板。

:render => :index