我正在使用 Best_in_Place gem 使我网站上的区域可编辑。我有两个模型:学生和教育,关系是每个学生都有_许多教育。在编辑直接在学生模型中的属性时,我可以使用 Best_in_place 功能,例如
<%=best_in_place @student, :name =>
但是,我无法用它来更新教育的属性。
<%=best_in_place @education, :college =>
在学生/节目的视图中,我
在 2012-03-25 13:06:57 -0400 收到错误 Started PUT "/educations" for 127.0.0.1
ActionController::RoutingError (没有路由匹配 [PUT] "/educations")
不仅不起作用,可编辑的位置也完全消失了。我不知道是什么导致了问题,两个模型/控制器的一切似乎都是一样的。我的路线很简单:
resources :students
resources :educations
root :to => 'pages#home'
devise_for :students
我的控制器也是如此:
def update
@student = Student.find(params[:id])
respond_to do |format|
if @student.update_attributes(params[:student])
format.html { redirect_to @student, notice: 'Student was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @student.errors, status: :unprocessable_entity }
end
end
end
对比
def update
@education = Education.find(params[:id])
respond_to do |format|
if @education.update_attributes(params[:education])
format.html { redirect_to @education, notice: 'Education was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @education.errors, status: :unprocessable_entity }
end
end
end
如果我耙路线,我会得到:
educations GET /educations(.:format) educations#index
POST /educations(.:format) educations#create
new_education GET /educations/new(.:format) educations#new
edit_education GET /educations/:id/edit(.:format) educations#edit
education GET /educations/:id(.:format) educations#show
PUT /educations/:id(.:format) educations#update
DELETE /educations/:id(.:format) educations#destroy
students GET /students(.:format) students#index
POST /students(.:format) students#create
new_student GET /students/new(.:format) students#new
edit_student GET /students/:id/edit(.:format) students#edit
student GET /students/:id(.:format) students#show
PUT /students/:id(.:format) students#update
DELETE /students/:id(.:format) students#destroy
任何指针都会有很大的帮助。