2012-03-25 152 views
1

我正在使用Best_in_Place gem使我的网站上的区域可编辑。我有两种模式:学生和教育,关系是每个学生都有一些教育。我有Best_in_place编辑功能可直接在学生模型的属性,如使用Best_in_Place编辑属性

<%=best_in_place @student, :name => 

然而,当工作时,我不能让它更新教育的属性。与像

线
<%=best_in_place @education, :college => 
在学生/显示视图

, 我得到的错误
开始在2012-03-25 13点06分57秒-0400

ActionController的PUT “/教育” 为127.0.0.1 :: RoutingError (没有ro ute匹配[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

你找到解决方案?我有同样的问题 – macler 2016-01-19 08:00:11

回答

0

两件事情:

  1. 你的看法语法是关闭的。您正在使用=>而不是%>关闭您的代码。因此,尝试这个:

    <%=best_in_place @student, :name %>

    <%=best_in_place @education, :college %>

  2. 尝试更新为format.jsonrespond_torespond_with_bip(@student)。这应该使用户能够通过javascript进行编辑,同时让用户在页面上通过AJAX查看更新。

See ReadMe for best_in_place Controller response with respond_with_bip

请参见下面的更新:

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 { respond_with_bip(@student) } 
    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: 'Student was successfully updated.' } 
     format.json { respond_with_bip(@education) } 
    else 
     format.html { render action: "edit" } 
     format.json { render json: @education.errors, status: :unprocessable_entity } 
    end 
    end 
end