下面是我在使用我的代碼的地方,我想我很接近。Sinatra CRUD每個模型的路線問題
savetomongoid是一個def,將params數組推向mongoid。
我使用的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
當我試着使用任何路徑來加載,我得到一個完全空白的屏幕,沒有源代碼,但是本地主機:#### /帶來我對我的哈姆:沉默,所以一些路線工作。
三個splats應該把它的價值模型,動作,id。我嘗試了一些東西/某些東西,但我仍然得到了無源頁面。
提示圖標和問號的模式假定通過自述上下工夫https://github.com/sinatra/sinatra
誰能給我個忙嗎?我幾乎肯定這應該工作。
此外,任何人都可以提出一種方法來檢查模型是否存在過濾掉模型中的任意東西生成crud?
你說得對,我拿出request.request_method,現在評估情況的方法。但是,在路線上有一個問題。它捕獲第一個圖示的值,但不是第二個或第三個。所以,無論我有什麼事,行動=「」......任何想法? – Theta