Noob with :method => :post vs. :post => 'true' dilemma


#1

Okay, I’ve worked through the tutorial in 2nd ed. Agile Dev book.

And I think I understand the methods concerning user management;
however, when I use :method => :post in my app, I get a link of the
following variety:

<li><a href="/login/delete_user/2" method="post" onclick="return

confirm(‘Really delete john?’);">[X]
john

Note the ‘method=“post”’, and in my log when I click this thing, no
‘post’ goes through, and no user gets deleted.

My delete_user method is identical to book’s.

However, when I use :post => ‘true’, no problem; post shows up in log,
and user gets deleted.

Generated code looks like:

<li><a href="/login/delete_user/1" onclick="if (confirm('Really

delete john?’)) { var f = document.createElement(‘form’);
this.parentNode.appendChild(f); f.method = ‘POST’; f.action =
this.href; f.submit(); };return false;">[X]

    john
</li>

What’s even stranger to me is that if I download the book’s code, which
has :method => :post in its list_users.rhtml template, and run that
app, it works just fine. What am I missing? I’m on rails 1.2.1, but am
really bewildered about the difference here.

Thanks for your patience.


#2

You should post the exact code that you are using. However, you are most
likely passing the arguments to the helper method incorrectly. They have
a rather strange parameter profile and you have to take great care where
you put the arguments and sometimes you need to explicitly surround them
with braces. The best example is probably directly from the Rails API
docs:

link_to “Delete Image”, { :action => “delete”, :id => @image.id },
:confirm => “Are you sure?”, :method => :delete

Notice how the second argument is explicitly made into a Hash using
braces. The remaining arguments are implicitly turned into another Hash
by Ruby and will be passed as the third argument.

If this doesn’t solve your problem, then post your exact code that
misbehaves.