使用此代码进行下面的编辑和更新操作。我面临2个问题
如何确定提交的表格(基本,照片,兴趣或详情?)
我已经设置了validates_presence_of所有配置文件字段,但是这个表单通常用于两个控制器操作(因此不是每个属性都匹配)并且我得到错误。
我该如何解决这个问题?
def edit
def sub_layout
"left"
end
@profile = Profile.find params[:id]
#authorize! :update, @profile
what = params[:what]
if ["basics", "location", "details", "photos", "interests"].member?(what)
render :action => "edit_#{what}"
else
render :action => "edit_basics"
end
end
def update
@profile = Profile.find(params[:id])
respond_to do |format|
if @profile.update_attributes(params[:profile])
format.html { redirect_to @profile, notice: 'Profile was successfully updated.' }
else
format.html {
#there was an error,
#redirect to the correct "what" form /edit/basics for example
# what is empty how to get the value or a better way for this?
what = params[:what]
render :action => "edit_#{what}"
}
end
end
end