这是我的代码所在,我认为我很接近。
savetomongoid 是一个将 params 数组推送到 mongoid 的 def。
我正在使用 activesupport 来支持复数和分类方法
route :get, :delete, :post, :put, '/*/*?/?*?' do |model, action, id|
case
when request.get?
case action
when "new"
haml '#{model}/new'
when "show"
instance_variable_set('@#{model}', model.classify.find(id))
haml '#{model}/show'
when "edit"
instance_variable_set('@#{model}', model.classify.find(id))
haml '#{model}/edit'
else
instance_variable_set('@#{model.pluralize}', model.classify.asc(made))
haml '#{model}/index'
end
when request.post? || request.put?
savetomongoid(model, params[model]) ? (redirect '/#{model}/') : (redirect '/#{model}/new')
when request.delete?
model.classify.find(id).delete ? (redirect '/#{model}/') : (puts "uhh ohh")
end
end
get '/*' do
haml :silence
end
当我尝试使用任何路径加载它时,我得到一个完全空白的屏幕,没有源,但是 localhost:####/ 将我带到我的 haml :silence ,所以一些路由正在工作。
这三个 splats 应该把它的价值放在模型、动作、id 中。我已经尝试过某事/某事/某事,但我仍然得到无源页面。
假设 splats 和问号的模式可以通过https://github.com/sinatra/sinatra上的自述文件工作
谁能帮我一把?我几乎可以肯定这应该有效。
另外,任何人都可以建议一种方法来检查模型是否存在以过滤掉模型中任意事物的生成残渣吗?