views:

19

answers:

1

Hi there,

I'm struggling with the following problem: What's the correct HTML (and/or Rails) code for

  • a button that resides within a form, and
  • that should lead to a new page, but
  • should not submit anything (from the form)?

Basically, the button should work exactly like a hyperlink.

Thanks for your help!

Tom

+1  A: 

You might try the "button_to" tag: Rails API

Tim
Unfortunately, this doesn't work: Usually, Rails would embed a submit button within an additional form. In my case, the button is already within a form, which apparently makes Rails drop the second additional form (probably because a form within a form is invalid HTML). Therefor, I'd end up with a submit button within a form, which POSTs the form - which should *not* happen...
TomDogg
Good point, I should've anticipated that. Well, there are a couple hacks. You could have a button image within a link (link_to image_tag ...), or you could use html/javascript for input type=button and have the onclick redirect you to a different page.
Tim
@Tim: Thanks - the javascript proposal is the best, given my conditions. In Rails speak, the code then become: button_to_function 'Go to new page' do |page| page.redirect_to whatever_path end
TomDogg