Update route and forms

17 views
Skip to first unread message

nathan

unread,
Mar 4, 2012, 5:51:35 PM3/4/12
to Pakyow
The routes section in the Pakyow manual shows a put method routing to
the update method given the /object/:id path. I am having trouble
updating a record using the form shown below. With or without the
itemprop='card[action]' attribute, when submitted the form always
redirects to the show method. My understanding is that Pakyow couldn't
find the specified route so it defaults to show.

<form id="card_form" action="/cards/8" method="put">
<span id="_card_fields">
<p><input class="no_input_border card_name" type="text"
name="card[name]" placeholder="Name" itemprop="card[name]"
value="sd"></p>
<p><textarea class="no_input_border card_content" cols="57" rows="12"
name="card[content]" placeholder="content" itemprop="card[content]"></
textarea></p>
<p><input class="no_input_border card_tags" type="text"
name="card[tag_list]" itemprop="card[tag_list]" placeholder="tags"
value="[]"><input class="no_input_border card_date" type="date"
name="card[date]" itemprop="card[date]" value="2012-02-27"><input
class="save_button" type="submit" value="save"></p>
</span>
</form>

Here's the resulting thin output. There's no errors, it just calls
show.

Processing /cards/8 (127.0.0.1 at 2012-03-04 16:49:36 -0600) [GET]
SHOW METHOD

I need help understanding the proper way to call the update action so
I can update my data. Thanks.

nathan

Bryan Powell

unread,
Mar 5, 2012, 9:37:04 AM3/5/12
to pak...@googlegroups.com
Unfortunately you can't submit a PUT request from a form. Pakyow solves this the same way other frameworks solve it, which is to submit a POST request with an additional field "_method". Changing the form method to "post" and adding this bit of code to your form should make it work properly:

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

Bryan

nathan claburn

unread,
Mar 5, 2012, 6:32:17 PM3/5/12
to pak...@googlegroups.com
Works perfectly, thanks!

Since this affects other frameworks this sounds like an HTML/HTTP issue, is that the case? 

Bryan Powell

unread,
Mar 5, 2012, 11:05:44 PM3/5/12
to pak...@googlegroups.com
Right, the problem is that browsers only support GET/POST requests from forms.
Reply all
Reply to author
Forward
0 new messages