ruby - Rails button_to parameter confusion -


i'm trying shove many parameters button_to method, no avail. i'm using rails docs see parameters can support -- i'm having trouble.

link api docs

<%= button_to 'my title.',{:action => "update", :answer => "!!===@@@", :method => :patch, :data => {:confirm => "are sure?"}}, {:class => "btn btn-danger"}%> 

i'm looking add html classes button, redefine http method, , call javascript prompt box (through :data, :confirm) , add :answer parameter submission content.

i'm having trouble getting rails parse correctly.

"as explains on page http://api.rubyonrails.org/classes/actionview/helpers/urlhelper.html , params (such :answer in case) can passed :params option.

the second argument needs can resolved full path, "/foos/123/update". can {:action => "update", :id => foo.id}: in case rails use current controller work out controller use in url. think it's cleaner explicit , use path helper update_foo_path(foo) or whatever, generate full path string oike "/foos/123/update".

try this:

<%= button_to 'my title.', {:action => "update", :id => foo.id}, :params => {:answer => "!!===@@@"}, :method => :patch, :form_class => "btn btn-danger", :data => {:confirm => "are sure?"} %> 

button_to kind of pain in ass because has list of arguments hashes or single key-value pairs , it's easy structure wrong. tend avoid them complicated, , use form_tag instead: it's more readable , less go wrong.


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -