我用我的Rails应用mongoig_slug宝石。
我可以创建正确的URL的对象,但我不能更新/删除对象,我必须在控制台中没有错误消息。 (I可以编辑的形式,其包含正确的数据)
我甚至用PRY在控制台检查,当我检查@book退出,是正确的,如果我做@ book.destroy它说真实的,但不破坏。 对于编辑,我也查@book,我还检查book_params这是正确的。
class Book
include Mongoid::Document
include Mongoid::Timestamps
include Mongoid::Slug
field :_id, type: String, slug_id_strategy: lambda {|id| id.start_with?('....')}
field :name, type: String
slug :name
end
class BooksController < ApplicationController
before_filter :get_book, only: [:show, :edit, :update, :destroy]
def update
if @book.update_attributes(book_params)
redirect_to book_path(@book)
else
flash.now[:error] = "The profile was not saved, please try again."
render :edit
end
end
def destroy
binding.pry
@book.destroy
redirect_to :back
end
def book_params
params.require(:book).permit(:name)
end
def get_book
@book = Book.find params[:id]
end
end