我正在使用Best_in_Place gem来使我的网站上的区域可以编辑。我有两个模型:学生和教育,关系是每个学生都有很多教育。在编辑直接在Student模型中的属性时,我有Best_in_place功能,例如
<%=best_in_place @student, :name =>
但是,我无法通过像
这样的行来更新教育的属性<%=best_in_place @education, :college =>
在学生/秀中,
我收到错误
在2012-03-25 13:06:57 -0400
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
VS
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
任何指针都将是一个巨大的帮助。
答案 0 :(得分:0)
两件事:
您的视图语法已关闭。您正在使用=>
而不是%>
关闭代码。所以试试这个:
<%=best_in_place @student, :name %>
<%=best_in_place @education, :college %>
尝试将respond_to
的{{1}}块更新为format.json
。这应该使用户能够通过javascript进行编辑,同时让用户在页面上通过AJAX查看他们的更新。
See ReadMe for best_in_place Controller response with respond_with_bip
请参阅以下更新:
respond_with_bip(@student)