0
我想製作一個按鈕,它改變了Object的布爾值。如何將params放入此行?
這一行:
= button_to 'Subscribe Back', candidate_subscriber_path(subscriber), method: :patch
這使得這個請求:
{"_method"=>"patch", "action"=>"update", "controller"=>"candidate/subscribers", "id"=>"2"}
我需要它來發送這些屬性:
subscribed: true
不知道往哪裏放他們。你有什麼線索嗎?
嘗試:
= button_to 'Subscribe Back', candidate_subscriber_path(subscriber, subscribed: true), method: :patch
= button_to 'Subscribe Back', { controller: 'subscribers', action: 'update', id: subscriber.id, subscribed: false }, method: :patch
夫婦的其他選項。
爲我的作品的唯一選項是:
= simple_form_for :subscriber, url: candidate_subscriber_path(subscriber),
html: { method: :patch } do |f|
= f.input :subscribed, as: :hidden, input_html: { value: '1' }
= f.button :submit, 'Subscribe Back'
看一看這一點;同樣的問題:http://stackoverflow.com/questions/5363153/rails3-pass-arbitrary-parameters-via-button-to – steakchaser
是的,試過 – user3007832
你可以在裏面添加「subscribed:true」= simple_form_for:subscriber,url: candidate_subscriber_path(用戶,訂閱:真) –