err212
err212

Reputation: 15

Pass value with link_to to the form on another page in rails

I need to pass a value for the form with a link_to to the 'new' page in rails.

'New' page form radio buttons code:

= f.collection_radio_buttons :model, books.all, :id, :model, :prompt => true, label: "Book"

So it will look like list of 5 radio buttons.

And i need pass a value to this radio buttons with:

= link_to "New", path_to_new_page

is it possible with rails only without javascript?

Upvotes: 1

Views: 1032

Answers (1)

Florin Ionce
Florin Ionce

Reputation: 855

Can't you just submit the form? It would be something like this

= form_for(@model_object, url: path_to_new_page(@model_object)) do |f|
   = f.collection_radio_buttons :model, books.all, :id, :model, :prompt => true, label: "Book"

   = f.submit "New"

You can find examples here -> http://guides.rubyonrails.org/form_helpers.html

If you can't/won't use form submit, you could just capture the click event, and just go to the new page with the parameters collected from the inputs.

Upvotes: 3

Related Questions