簡體   English   中英

使用Best_in_Place編輯屬性

[英]Using Best_in_Place to edit attributes

我正在使用Best_in_Place寶石使我網站上的區域可編輯。 我有兩個模型:學生模型和教育模型,每個學生都有很多教育。 當編輯直接在Student模型中的屬性時,例如,我具有Best_in_place功能,例如

<%=best_in_place @student, :name =>

但是,我無法用這樣的行來更新教育的屬性。

<%=best_in_place @education, :college =>

在學生/表演的角度來看,我得到了錯誤
在2012-03-25 13:06:57 -0400開始針對127.0.0.1的PUT“ /教育”

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

任何指針都會有很大的幫助。

兩件事情:

  1. 您的視圖語法已關閉。 您正在使用=>而不是%>關閉標簽。 因此,請嘗試以下操作:

    <%=best_in_place @student, :name %>

    <%=best_in_place @education, :college %>

  2. 嘗試更新respond_toformat.jsonrespond_with_bip(@student) 這應該使用戶能夠通過javascript進行編輯,同時將用戶留在頁面上以通過AJAX查看其更新。

請參閱自述文件以獲取關於resin_with_bip的best_in_place控制器響應

請參閱下面的更新:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM