我按照#302 In-Place Editing 截屏教程来实现 best_in_place。
视图位于visitors
到目前为止,编辑工作正常。但是,在我按 Enter 后它无法保留更改,并且出现 javascript 错误:
POST http://localhost:3000/visitors 404 (Not Found)
在我的访问者/new.html.erb 中,我实现了:
<%= best_in_place @visitor, :special %>
在我的 visitor_controller.rb 中,我实现了:
class VisitorsController < ApplicationController
respond_to :html, :json
def show
@visitor = Visitor.find(params[:id])
end
def new
@visitor = Visitor.new
end
def create
@visitor = Visitor.new(secure_params)
if @visitor.valid?
@visitor.update_spreadsheet
flash[:notice] = "Chose #{@visitor.favorite}."
render :new
else
render :new
end
end
def update
@visitor = Visitor.find(params[:id])
@visitor.update_attributes(secure_params)
respond_with @visitor
end
private
def secure_params
params.require(:visitor).permit(:favorite, :comment)
end
end
在我的 application.js 中,我有:
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require bootstrap
//= require_tree ./bootstrap
//= require_tree ./styler
//= require social-media
//= require users
//= require jquery.purr
//= require best_in_place
$(document).ready(function() {
$('.best_in_place').best_in_place();
});
知道如何解决这个问题吗?如果我需要提供更多信息,请告诉我。
编辑:
Prefix Verb URI Pattern Controller#Action
GET|POST /auth/:provider/callback(.:format) sessions#create
auth_failure GET|POST /auth/failure(.:format) redirect(301, /)
signout GET|POST /signout(.:format) sessions#destroy
supports POST /supports(.:format) supports#create
new_support GET /supports/new(.:format) supports#new
menus_sandwiches GET /menus/sandwiches(.:format) menus#sandwiches
menus_catering GET /menus/catering(.:format) menus#catering
menus_breakfast GET /menus/breakfast(.:format) menus#breakfast
menus_salads GET /menus/salads(.:format) menus#salads
menus_smoothies GET /menus/smoothies(.:format) menus#smoothies
menus_desserts GET /menus/desserts(.:format) menus#desserts
visitors POST /visitors(.:format) visitors#create
new_visitor GET /visitors/new(.:format) visitors#new
menus POST /menus(.:format) menus#create
new_menu GET /menus/new(.:format) menus#new
root GET / visitors#new
page GET /pages/*id high_voltage/pages#show