出于某种原因,我的"PUT"方法没有被Sinatra使用这个html捕获.有人能帮我发现错误吗?当我在我的控制器中使用"post"动作时,它的工作方式与预期的一样......
<form method="post" action="/proposals/<%=@proposal.id%>/addItem">
<input type="hidden" name="_method" value="put"/>
<div>
<label for="item_id">Item list</label>
<select title="Item ID" id="item_id" name='item_id'>
<%@items.each do |item|%>
<option value="<%=item.id%>"><%=item.name%></option>
<%end%>
</select>
<input type="submit" value="Add"/></div>
<label for="new_item_name">Create new item</label>
<input type="text" id="new_item_name" name="new_item_name" />
<input type="submit" value="Create"/>
</form>
Run Code Online (Sandbox Code Playgroud)
efo*_*foo 14
一定要包含Rack::MethodOverride在你的config.ru中:
use Rack::MethodOverride
Run Code Online (Sandbox Code Playgroud)
Abo*_*uby 10
一切看起来都正确.看起来你要么写错了路由字符串,要么在put方法之前被另一条路由捕获.我很好奇这个,所以我写了一个使用put方法的快速Sinatra应用程序,它确实以这种方式工作.
#!/usr/bin/env ruby
require 'rubygems'
require 'sinatra'
get '/' do
<<-eos
<html>
<body>
<form action="/putsomething" method="post">
<input type="hidden" name="_method" value="put" />
<input type="submit">
</form>
</body>
</html>
eos
end
put '/putsomething' do
"You put something!"
end
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5978 次 |
| 最近记录: |