我正在尝试将 jeditable 与我的 rails 3 应用程序一起使用。我想内联编辑一些字段。
我的观点
<script>
jQuery(document).ready(function($) {
$(".edit_textfield").each( function() {
$(this).editable('update', {
type :'textarea',
cancel :'Cancel',
submit :'OK',
indicator :'Saving...',
tooltip :'Click to edit...',
rows :10,
method :"PUT",
submitdata :{id: $(this).attr('id'), name:$(this).attr('name') }
});
});
});
</script>
<p id="notice"><%= notice %></p>
<p>
<b><%=t :Name%>:</b>
<dd class="edit_textfield" id="<%= @student.id %>" name="name"><%= @student.name %></dd>
</p>
<p>
<b><%=t :Age%>:</b>
<dd class="edit_textfield" id="<%= @student.id %>" name="age"><%= @student.age %></dd>
</p>
<p>
<b><%=t :Address%>:</b>
<dd class="edit_textfield" id="<%= @student.id %>" name="address"><%= @student.address %></dd>
</p>
<p>
<b><%=t :Phone%>:</b>
<dd class="edit_textfield" id="<%= @student.id %>" name="phone"><%= @student.phone %></dd>
</p>
我的控制器:
def update
@student = Student.find(params[:id])
@student.name = params[:value]
@student.age = params[:value]
@student.address = params[:value]
@student.phone = params[:value]
@student.save
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
错误
Processing by StudentsController#update as HTML
Parameters: {"id"=>"update", "value"=>"Sreekesh O S", "name"=>"name"}
WARNING: Can't verify CSRF token authenticity
Student Load (1.6ms) SELECT `students`.* FROM `students` WHERE `students`.`id` = 0 LIMIT 1
Completed 500 Internal Server Error in 6ms
ActiveRecord::RecordNotFound (Couldn't find Student with id=update):
app/controllers/students_controller.rb:59:in `update'
有谁知道如何纠正这个问题?