tags:

views:

59

answers:

1

For some reason, my "PUT" method isn't caught by Sinatra using this html. Can someone help me spot the mistake? When I use a "post" action in my controller, it works just the way it is expected...

<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>
+2  A: 

That all looks correct. It looks like you either wrote the route string wrong, or it's being caught by another route before your put method. I was curious about this so I wrote up a quick Sinatra app that used a put method, and it does indeed work this way.

#!/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
AboutRuby