【发布时间】:2012-05-01 14:35:36
【问题描述】:
这是我的代码所在,我认为我已经接近了。
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 上的自述文件工作
谁能帮帮我?我几乎可以肯定这应该有效。
另外,任何人都可以建议一种方法来检查模型是否存在以过滤掉模型中任意事物的生成杂物吗?
【问题讨论】: