我有一个表格
<%= form_for([@group, lesson], remote: true) do |f| %>
<tr id='<%= lesson.id%>' >
<td><%= f.text_field :time %></td>
<td><%= f.text_field :day %></td>
<td><%= f.text_field :subject %></td>
<td><%= f.text_field :teacher %></td>
<td><%= f.text_field :room %></td>
<td><%= f.submit 'Update'%></td>
<td><%= link_to 'Delete', [lesson.group, lesson], remote: true,method: :delete%></td>
</tr>
<%end%>
控制器
def update
@lesson = @group.lessons.find(params[:id])
@lesson.update_attributes(params[:lesson])
respond_to do |format|
if @lesson
format.html { redirect_to edit_group_path(@group), notice: 'Succesfully updated lesson' }
format.js { render :json => @lesson, location: edit_group_path(@group) }
format.json { render json: @lesson}
else
format.html { redirect_to edit_group_path(@group), notice:'Error!' }
format.json { render json: @lesson }
end
end
end
和 JS
$(document).ready ->
$('#new_lesson').on("ajax:success", (e, data, status, xhr) ->
$('.notice').append data
).bind "ajax:error", (e, xhr, status, error) ->
$('.notice').append '<p>ERROR:'+error+'</p>'
$(".edit_lesson").on("ajax:success", (e, data, status, xhr) ->
$('.notice').append data
).bind "ajax:error", (e, xhr, status, error) ->
$('.notice').append '<p>ERROR:'+error+'</p>'
请求很好,当我单击按钮时条目会更新。但它总是将语法错误抛出到“.notice”中:
SyntaxError:意外的令牌:
在互联网上找到的其他解决方案对我没有帮助