2010-08-23 3 views
4

어떤 이유로,이 "html"을 사용하여 Sinatra에 "PUT"메소드가 걸리지 않았습니다. 누군가 내가 실수를 발견하도록 도울 수 있습니까? 내 컨트롤러에서 "게시물"작업을 사용할 때 예상대로 작동합니다. ...Sinatra PUT 방법이 작동하지 않습니까?

<form method="post" action="/proposals/<%[email protected]%>/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> 
+0

method = "post"? – rogerdpack

+0

Sinatra Book에 따라 필요에 따라. –

답변

9

모두 올바르게 보입니다. 경로 문자열을 잘못 작성했거나 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 
12

당신의 config.ru에 Rack::MethodOverride을 포함해야합니다 : 도움이 위의 난 그냥 이것으로 실행되지 않으며 정보가 전혀

use Rack::MethodOverride 
0

.

양식 정의가 조치를 먼저 와야 = 및

올바른 양식 = 방법으로 두 번째 : 나는 무엇을 발견

<form action="/putsomething" method="POST"> 
    <input type="hidden" name="_method" value="PUT" /> 
... 
</form> 

잘못된 형태 :

<form method="POST" action="/putsomething"> 
    <input type="hidden" name="_method" value="PUT" /> 
... 
</form> 

처음에는 나를 위해 일했지만 두 번째는하지 않았습니다. 아마도 도움이됩니다.

관련 문제