Strange form_tag behaviour

I am trying to use a GET form to produce a URL of the form:
…/project/show/123

If I use:
<%= form_tag ({ :action => ‘show’, :id => @project.id}, :method => ‘get’
) %>

<%= submit_tag ‘go’ %>
<%= end_form_tag %>

I get a URL back of the form:
…/projects/show/559?project%5Bid%5D=673&commit=go

The problems here are:

  1. The parameters are appended on the original URL
    (…/projects/show/559). Why is the previous id still showing?

  2. The whole “project id = 673” and “commit = go” are present. I just
    want the id number as shown above.

Help! This is driving me mad. Any help much appreciated for a rails
newbie!

Thanks
Nick

Nick McFarlane wrote:

  1. The parameters are appended on the original URL
    (…/projects/show/559). Why is the previous id still showing?

  2. The whole “project id = 673” and “commit = go” are present. I just
    want the id number as shown above.

Help! This is driving me mad. Any help much appreciated for a rails
newbie!

Thanks
Nick

Nick, I’m a newbie too, but I find that sometimes if I give a stupid
answer, it ruffles the feathers of an expert enough that they chime in
with the right answer.

  1. I would try using session[:project_id] to keep track of your id. You
    have to set it somewhere where it is known, and then it should be
    available from pretty much anywhere. You can’t count on a global to
    keep the right value between updates.

  2. sorry, no clue on this one…leaving out “:id => @project.id” will
    get you closer, but I don’t know how to get rid of the commit part.

best,
jp

Jeff, thanks for your input

  1. I would try using session[:project_id] to keep track of your id. You
    have to set it somewhere where it is known, and then it should be
    available from pretty much anywhere. You can’t count on a global to
    keep the right value between updates.

Yes, I could use the session to hold project.id. I thought (!) it would
be simpler just to post it in the url. This is a good application of
“GET” requests, since it does not change the page and users can bookmark
it.

  1. sorry, no clue on this one…leaving out “:id => @project.id” will
    get you closer, but I don’t know how to get rid of the commit part.

Leaving out “:id…” doesn’t make any difference.

Another observation:

The generated html for a typical page is:

...

So I can see that it thinks the action is “/projects/show/559” and not
“projects/show” - weird!

Thanks again
nick