开发者

Ruby on Rails issue, form supposed to issue a PUT, a GET comes through instead

Probably a NOOB issue. I have a form that is supposed to issue a PUT but instead it comes through as a GET. Not sure where I am going wrong.

Route (from Rake Routes):

PUT    /jira/jira_projects/:id(.:format)              {:action=>"update", :controller=>"jira/jira_projects"}

Form with Java Script:

<h1><%= @title %></h1>

<form action="/jira/jira_projects/" method="put">
  <div id="home">
    <div class="yui-g">
      <div class="panel">
        <h2>Project Details</h2>
        <div class="panelBody">
          <div id="project" class="innerPanelBody">
            <input type="hidden" name="id" id="id" value="<%= @project.id %>">

            <label for="name">Name:</label>
            <input type="text" name="jira_name" id="name" value="<%= @project.jira_name %>">

            <br>
            <br>

            <label for="application_ids">Applications Name:</label>
            <select id='application_ids' name='death_burrito_application_ids[]' class="graph" multiple="multiple" size="5">
              <% @all_applications.each do |a| %>
                <% if @applications.detect {|x| x.id == a.id } %>
                  <option selected="selected" value="<%= a.id %>"><%= a.death_burrito_name %>
                <% else %>
                  <option value="<%= a.id %>"><%= a.death_burrito_name %>
                <% end %>
              <% end %>
            </select>

            <br>
            <br>

            <input type="submit" value="Update" class="submit_button">
            <input type="button" class="s开发者_运维知识库ubmit_button" name="Cancel" value="Cancel" onclick="window.location = '../../../' " />

            <br>
          </div>
        </div>
      </div>
    </div>
  </div>

  $(document).ready(function() {
  function showValues() {
    var str = $("form").serialize();
    $("#results").text(str);
  }
  $("select").change(showValues);

  $('#submit_button').click(function() {
    showValues();
    window.location = "/jira/jira_projects/" + $("#results").text();
    return false;
  });

});

Entry in the Log:

Started GET "/jira/jira_projects/?id=3&jira_name=ApplyWeb&death_burrito_application_ids%5B%5D=32&death_burrito_application_ids%5B%5D=39&death_burrito_application_ids%5B%5D=40" for 127.0.0.1 at Thu Aug 25 17:07:28 -0700 2011
  Processing by Jira::JiraProjectsController#index as HTML 


You can only use a GET or a POST in a HTML form:

http://www.w3.org/TR/html4/interact/forms.html#h-17.3

For Rails, use POST in your html form, and then include a hidden input with name "_method" and value "put":

<input type="hidden" name="_method" value="put" />

This is also how you would issue a DELETE (change "put" to "delete" in the value).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜