Forum: Ruby on Rails noob with :method => :post vs. :post => 'true' dilemma

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
F2cc2eb5f57d402541c6a97b9a0ddb3a?d=identicon&s=25 chriso1515@gmail.com (Guest)
on 2007-01-22 01:40
(Received via mailing list)
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]</a>
        john
    </li>

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]</a>

        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.
7e483d1e04ad24c9a8e0612ed14e8f72?d=identicon&s=25 Per Velschow (pervel)
on 2007-01-22 06:29
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.
This topic is locked and can not be replied to.